Parse: withoutDataWithClassName is now outDataWithClassName? - ios

I've migrated my iOS parse SDK from the old Parse SDK to the version released to support a Parse stack hosted on my own infrastructure.
I have my project set up with SocketIO and decided it would be more efficient to append new Parse Objects sent from the server to my iOS apps model instead of making a new network request whenever the model changed, therefore I needed to instanciate a Parse object with an existing object ID.
To do that I used the following code snippet:
let appendError = PFObject(withoutDataWithClassName: "MachineError", objectId: id)
appendError.setValue(errorCode, forKey: "errorCode")
appendError.setValue(errorMessage, forKey: "errorMessage")
appendError.setValue(newDate, forKey: "createDate")
appendError.setValue(serial, forKey: "serialNumber")
appendError.setValue(status, forKey: "status")
appendError.setValue(false, forKey: "completed")
This code used to work fine when I was running xcode v7.1 but since this-morning when I upgraded to xcode 7.3, I was presented with an error that withoutDataWithClassName was not a valid parameter, it offered me outDataWithClassName as an alternative but the naming of that parameter did not sound as declarative as the previous. I did some reading through the PFObject documentation for iOS, but I could not find any details depicting what outDataWithClassName actually does.
I can only assume that it may be a typo on behalf of the Parse team, but I may be wrong. Could anyone here confirm whether withoutDataWithClassName is equivalent to outDataWithClassName?

Looks like it was a mistake related to automatic Objective-C to Swift conversion. It was reported as in issue in the repo, and a fix was committed 3 days ago.
In short, outDataWithClassName will do the same thing as withoutDataWithClassName for now, but since the current method name is rather uninformative, I would recommend updating Parse soon to get the fix.

Related

iOS Firebase - Crash in simulator but not device w/ persistence

I tried googling this problem but it seems like everyone has the opposite problem where the app runs on simulator but not their device. I've been struggling a LOT all week with firebase asynchronous calls returning null and linked the issue to persistence being enabled. All my problems go away if I disable persistence, but I want it enabled. I learned recently about synchronous issues with the different listeners/persistence and have been struggling with firebase returning outdated/nil values for a while.
Simulator was working just a week or two ago and I'm not sure what's changed. I've tried messing with / switching out .observeSingleEvent for .observe and still crashes at this code:
let synced = ref.child("profiles").child((FIRAuth.auth()?.currentUser?.uid)!).child("level")
synced.observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
print(snapshot)
print(snapshot.ref)
if (snapshot.value as! String == "One") {
........//CRASH
With the message:
Could not cast value of type 'NSNull' (0x10b7cf8c8) to 'NSString' (0x10a9dfc40).
When I try to print snapshot, it shows me an empty snapshot. But when I print the ref, the link works and takes me to the right place in my db (where I can see the data exists)
Any ideas how to fix/get around this without disabling persistence? Or more importantly I guess, should I care that it doesn't work in simulator if it works on a device? Will this matter for app store approval / affect future users?
If you'd like to see for yourself that this is an issue of firebase getting a nil/outdated value when the reference exists, here is what I see when I follow the printed ref link
The error seems fairly explicit: there is no value, so you can't convert it to a string.
synced.observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
if (snapshot.exists()) {
if (snapshot.value as! String == "One") {
........//CRASH

Trying to use Realm Object Server Tutorial

I have created an Amazon Web Services EC2 instance and deploy one of the AMIs with a Realm Object Server as its documentation explains:
https://realm.io/docs/realm-object-server/#install-realm-object-server
Once installed and created my admin user, I have completed the iOS tutorial: https://realm.io/docs/tutorials/realmtasks/, just until point 7, enough for creating task, but when I add new task in app, nothing happens. Debugging, I notice that next sentence try, is not executing:
let items = self.items
try! items.realm?.write {
items.insert(Task(value: ["text": text]), at: items.filter("completed = false").count)
}
The items collection seems to be initialized properly:
In the ROS dashboard, can see the database referenced in Xcode:
In image can be see "Default permissions" property is no access, is this the reason of not creating new task? If so, how can I change that permissions? If that is not the reason, anyone could help me?
thanks in advance
The problem was that I did not follow al the complete tutorial because I do not want to use the desktop application, just mobile example, but realm init objects in desktop app, so I never got a valid realm where perform actions.
For a quick and simple start with this realm tutorial pointing to an online server, not local, you must initialize the TaskList object and add it to self.realm on setup
// Show initial tasks
func updateList() {
if self.realm.objects(TaskList.self).count == 0 {
let list = TaskList()
list.id = "000001"
list.text = "lista de prueba"
// Add to the Realm inside a transaction
try! self.realm.write {
self.realm.add(list)
}
}
if self.items.realm == nil, let list = self.realm.objects(TaskList.self).first {
self.items = list.items
}
self.tableView.reloadData()
}
checking if there is not a TaskList with if self.realm.objects(TaskList.self).count == 0 {, you can create one and init realm.
You probably forgot to launch Mac demo app first or login with a different user. The tutorial assumes that existing data will be synced at login. If you have never launched the Mac app or logged in a different user, it may happen that items are not managed by Realm.
The tutorial says the following:
First, please follow the Get Started instructions to get set up with the Realm Mobile Platform and to launch the macOS version of RealmTasks.
Also, you attempt to try this tutorial with ROS on AWS. The tutorial assumes running ROS on a same local machine.
So you should modify the Mac app code to connect to the AWS, then run it to synchronize the initial data. Then run the tutorial iOS app.
The default permissions here show whether all other users can access the Realm or not, which isn't the case here. We already have an internal issue around clarifying this.
The registered user who owns the Realm has individual permissions to it by default. If you wouldn't have permissions opening the synchronized Realm from the client would also fail because of insufficient permissions, so this isn't the problem here.
So going back to your code:
try! items.realm?.write { … }
My guess would be that the problem here is that the collection isn't already attached to a Realm, so that items.realm? evaluates to null. In that case the write transaction wouldn't be executed.
You can resolve this by making sure to add the items first to a Realm or executing the write directly on a synchronized Realm.

Could not cast value of type 'SPTSession' (0x110afab98) to 'SPTSession' (0x10f17f638)

I am using the Spotify iOS SDK and I am storing a session using NSKeyedUnarchiver
However the following code causes an error(some code omitted just for clarity's sake):
sptSession = NSKeyedUnarchiver.unarchiveObjectWithData(sessionData as! NSData)
let auth = SPTAuth.defaultInstance()
auth.session = sptSession as! SPTSession
The last line of code is throwing the error Could not cast value of type 'SPTSession' (0x110afab98) to 'SPTSession' (0x10f17f638). I read that error as somehow there are two different types of SPTSessions but I'm not sure why or how to resolve the issue.
the answer seems to be related to this SO post:
Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?
I have added an issue to the GH repo for Spotify's iOS SDK (https://github.com/spotify/ios-sdk/issues/759), and posted this temporary workaround as a comment on the issue:
for the time being, I have found a workaround - I can simply write NSKeyedArchiver.setClassName("SPTSession", for: SPTSession.self) before I archive the session, and write NSKeyedUnarchiver.setClass(SPTSession.self, forClassName: "SPTSession") before unarchiving.
While this fixes the crash, I will leave the issue open as I am not sure if a change can be made in the underlying library to fix this

Firebase childbyAutoId returns the same strange key every time

When using childByAutoId, something really strange happens. Instead of getting a unique id, I get the following key every time:
-------------------0
I know keys are generated with client side timestamps, so I tried running my code through the iOS simulator and an actual device, same result though.
I don't do anything interesting in my code, but here it is for reference:
func sendRandomMessage() {
let firebaseRootRef = Firebase(url:firebaseRootUrl)
let newMessageRef = firebaseRootRef.childByAutoId()
println(newMessageRef.key)
}
I'm using Firebase 2.3.0
There was a bug in the Firebase SDK for iOS 2.3.0 that caused this problem.
It has been fixed in 2.3.1. See https://www.firebase.com/docs/ios/changelog.html

GAIDictionaryBuilder fails for NSNumber values

I am trying to send commerce transaction data to google analytics on iOS with V3 SDK. I am building the data dictionary using GAIDictionaryBuilder class provided by Google (which is not open source unfortunately). For both createTransactionWithId and createItemWithTransactionId calls, my NSNumber values (revenue, price, etc.) are failing to be added to dictionary data properly. Here is the sample code:
NSMutableDictionary* test = [[GAIDictionaryBuilder createTransactionWithId:(NSString *)transactionId
affiliation:(NSString *)affiliation
revenue:(NSNumber *)revenue
tax:(NSNumber *)tax
shipping:(NSNumber *)shipping
currencyCode:(NSString *)currencyCode] build];
NSLog(#"revenue: %#", revenue);
NSLog(#"TR data: %#", test);
// if I explicitly set the value, IT WORKS!!!!
[test setObject:revenue forKey:#"&tr"];
NSLog(#"TR data FIXED??: %#", test);
In the output, I see revenue correctly, then when logging test dictionary I see the following line corresponding to revenue data:
"&tr" = "<null>";
Then, for the manual fix attempt, I see
"&tr" = "15.25";
as expected.
Here are some clues:
I use the same code in a different project compiled in a different OSX machine without any issues like this.
The transactions are in TRY (Turkish Lira), I suspect Google is trying to fix the separator (',' in Turkish vs '.' everywhere else), but as said above, the other app is also using TRY.
So the question is, why "<null>", why and how does it fail to convert a proper NSNumber to this bizarre value?
Eventually, I fixed the issue by working around it. I assigned the NSNumber to a new one (by getting its floatValue) and it seemed to fix the null values.
By the way, google analytics library version 3.07 readme mentions a similar issue as fixed however neither 3.03 nor 3.07 actually fixed my problem.

Resources