I am trying to get Parse push notifications working on my app (all swift) but while trying to implement, I get the error 'PFInstallation' does not have a member named 'saveInBackground'
Here is my code.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("APP ID HIDDEN", clientKey: "CLIENT ID HIDDEN")
// let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
//let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
var notificationType: UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
//UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
// Override point for customization after application launch.
return true
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings!) {
UIApplication.sharedApplication().registerForRemoteNotifications()
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
var currentInstallation: PFInstallation = PFInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.saveInBackground()
println("got device id! \(deviceToken)")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println(error.localizedDescription)
println("could not register: \(error)")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
}
When I change the currentInstallation.saveInBackground
to currentInstallation.saveEvenutally()
, the code compiles fine..
But when trying to successfully sign up for push notifications, an error pops up in the console saying Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)
I have spent hours trying to figure this out, no dice, any help is appreciate.
To register to receive push notifications via Apple Push Service you have to call a registerForRemoteNotifications() method of UIApplication . If registration succeeds, the app calls your app delegate object's application:didRegisterForRemoteNotificationsWithDeviceToken: method and passes it a device token.
To anyone else who has this error, make sure you import the Bolts framework into your Bridging Header file
Which isn't outlined in their crap docs.
That fixes the issue.
Below is the code.
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
Just add that to your bridging header then you are good to go. Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With