Reputation:
I have a UISwitch in my app which I want to register and unregister push notifications. I am currently using parse and I want the app to update to devicetoken in the usertable on the server as well. I'm using this code but it crashes when I flip the switch. "Can't use nil for keys or values on PFObject."
So how would I deal with dropping the value from the current installation and usertable if I can't set to nil.
UIApplication.sharedApplication().unregisterForRemoteNotifications()
switchValue.setOn(false, animated: true)
installation.deviceToken = nil
user["devicetoken"] = nil
user.saveInBackground()
Upvotes: 3
Views: 1235
Reputation: 3854
You should use removeObjectForKey
on PFObject. that way when you get back same data from parse, you will get nil, not an empty string
Upvotes: 4
Reputation: 13333
Just use user["devicetoken"] = ""
, and be sure to check for a blank string before trying to use the token to send a notification.
Upvotes: -1