解析推送通知-Swift安装不工作
我正在尝试在我的应用程序上获取解析推送通知(全部为swift),但在尝试实现时,出现错误解析推送通知-Swift安装不工作,swift,notifications,parse-platform,push,Swift,Notifications,Parse Platform,Push,我正在尝试在我的应用程序上获取解析推送通知(全部为swift),但在尝试实现时,出现错误“PFInstallation”没有名为“saveInBackground”的成员 这是我的密码 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { Parse.setApplicationId("A
“PFInstallation”没有名为“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.saveevenutaly()
时,代码编译得很好
但是,当尝试成功注册推送通知时,控制台中会弹出一个错误,说明此操作中必须指定error:deviceType(代码:135,版本:1.4.2)
我花了几个小时试图弄明白这一点,没有骰子,任何帮助都是感激的
有效的PFInstallation只能通过[PFInstallation currentInstallation]实例化,因为所需的标识符字段是只读的。()
因此,不是:
var currentInstallation: PFInstallation = PFInstallation()
尝试:
对于出现此错误的任何其他人,请确保将Bolts框架导入到桥接头文件中
这在他们的垃圾文件中没有列出
这就解决了问题
下面是代码
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
#导入
#进口
只需将其添加到你的桥接标题中,你就可以开始了。谢谢只需在AppDelegate.swift文件中写入导入螺栓
除了导入螺栓,我还通过将函数更改为
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// Store the deviceToken in the current Installation and save it to Parse
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
}
从推送通知解析指南(与快速启动指南相反):好的,这没什么作用。仍然存在错误“'PFInstallation'没有名为'saveInBackground'的成员”,它获得的设备ID很好,只是不会在Parse一侧注册为安装。它不会收到推送消息,除非您使用save方法,否则您不会收到推送消息。由于某种原因,currentInstallation
是否是可选的?选项单击它,查看它是否属于PFInstallation?
类型。我看不出它是可选的。我不知道该告诉你什么!您确定您所在的解析版本中存在saveInBackground
,并且您的对象不是可选的(PFInstallation!
或PFInstallation?
)?”这是一个正在工作的实现…这对我来说仍然无法修复:(,执行此操作+var currentInstallation:PFInstallation=PFInstallation.currentInstallation()已工作import Bolts
就是这样这应该是可接受的答案。当前可接受的答案不起作用。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// Store the deviceToken in the current Installation and save it to Parse
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
}