我正在尝试使用Parse推送通知在我的应用上运行(所有swift)但在尝试实现时,我收到错误'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)
}
当我将currentInstallation.saveInBackground
更改为currentInstallation.saveEvenutally()
时,代码编译得很好..
但是在尝试成功注册推送通知时,控制台中会弹出一个错误Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)
我花了好几个小时试图解决这个问题,没有骰子,任何帮助都是值得欣赏的。
答案 0 :(得分:22)
对于出现此错误的任何其他人,请确保将Bolts框架导入您的桥接头文件
在他们的废话文档中没有概述。
这解决了这个问题。
以下是代码。
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
只需将其添加到您的桥接标题即可。感谢
答案 1 :(得分:7)
有效的PFInstallation只能通过[PFInstallation currentInstallation]实例化,因为所需的标识符字段是只读的。 (source)
所以而不是:
var currentInstallation: PFInstallation = PFInstallation()
尝试:
var currentInstallation = PFInstallation.currentInstallation()
答案 2 :(得分:4)
只需在AppDelegate.swift文件中写import Bolts
答案 3 :(得分:2)
除了导入Bolts之外,我还通过将功能更改为
在我的应用中修复了相同的错误T1, T2, I
来自推送通知的解析指南(与快速入门指南相对):https://parse.com/docs/ios/guide#push-notifications