Mat*_*son 8 notifications push parse-platform swift
我试图在我的应用程序(所有swift)上运行Parse推送通知,但在尝试实现时,我收到错误 'PFInstallation' does not have a member named 'saveInBackground'
这是我的代码.
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)
}
Run Code Online (Sandbox Code Playgroud)
当我更改currentInstallation.saveInBackground为currentInstallation.saveEvenutally(),代码编译正常..
但在尝试成功注册推送通知时,控制台中会弹出一个错误消息 Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)
我花了好几个小时试图解决这个问题,没有骰子,任何帮助都是值得欣赏的.
Mat*_*son 22
对于出现此错误的任何其他人,请确保将Bolts框架导入到桥接头文件中
在他们的废话文档中没有概述.
这解决了这个问题.
下面是代码.
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
Run Code Online (Sandbox Code Playgroud)
只需将其添加到您的桥接标题即可.谢谢
有效的PFInstallation只能通过[PFInstallation currentInstallation]实例化,因为所需的标识符字段是只读的.(来源)
所以代替:
var currentInstallation: PFInstallation = PFInstallation()
Run Code Online (Sandbox Code Playgroud)
尝试:
var currentInstallation = PFInstallation.currentInstallation()
Run Code Online (Sandbox Code Playgroud)