我正在尝试让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)
}当我将currentInstallation.saveInBackground改为currentInstallation.saveEvenutally()时,代码编译得很好。
但是,当尝试成功地注册推送通知时,控制台中会弹出一个错误,上面写着Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)。
我花了好几个小时试图弄清楚,没有骰子,任何帮助都是感激的。
发布于 2014-10-24 07:53:44
对于其他有此错误的人,请确保将Bolts框架导入桥接头文件中。
在他们的垃圾文件里没有提到。
这就解决了问题。
下面是密码。
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>只要把这个加到你的桥接头上,你就可以走了。谢谢
发布于 2014-10-22 05:48:46
有效的PFInstallation只能通过PFInstallation currentInstallation实例化,因为所需的标识符字段是只读的。(来源)
因此,与其:
var currentInstallation: PFInstallation = PFInstallation()尝试:
var currentInstallation = PFInstallation.currentInstallation()发布于 2015-08-06 12:41:31
只需在您的import Bolts文件中写入AppDelegate.swift
https://stackoverflow.com/questions/26500928
复制相似问题