Ios 解析设置设备令牌
我正在尝试在解析中设置设备令牌。官方文档给出了执行此操作的以下代码 正式文件(目标C) 我已按如下方式转换代码,但收到一个错误 我的代码(Swift) 我在运行代码时收到以下错误:Ios 解析设置设备令牌,ios,xcode,swift,parse-platform,Ios,Xcode,Swift,Parse Platform,我正在尝试在解析中设置设备令牌。官方文档给出了执行此操作的以下代码 正式文件(目标C) 我已按如下方式转换代码,但收到一个错误 我的代码(Swift) 我在运行代码时收到以下错误: Break on warnBlockingOperationOnMainThread() to debug. 2014-11-13 03:44:01.306 Meetr[8855:2084537] Error: invalid type for key deviceToken, expected array, bu
Break on warnBlockingOperationOnMainThread() to debug.
2014-11-13 03:44:01.306 Meetr[8855:2084537] Error: invalid type for key deviceToken, expected array, but got string (Code: 111, Version: 1.4.2)
sent
有人能帮我解释一下为什么会这样吗?我很困惑,因为我只是简单地将原来的objective C代码转换为swift
提前感谢。错误表明类型错误:
Error: invalid type for key deviceToken, expected array, but got string (Code: 111, Version: 1.4.2)
只需将数据从字符串(“deviceToken”)更改为数组([“deviceToken”])。我刚刚设置了解析通知,没有任何问题。你有错误的那一行正是我有错误的那一行,所以我不认为这就是问题所在。以下是我在应用程序中拥有的一切:
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
//ENABLE PUSH NOTIFICATIONS
let userNotificationTypes = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound)
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return true
}
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
//Store the deviceToken in the current installation and save it to Parse.
let currentInstallation: PFInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.saveInBackground()
}
func application(application: UIApplication!, didReceiveRemoteNotification userInfo: NSDictionary!) {
PFPush.handlePush(userInfo)
}
不确定问题是从什么开始的,但是,删除类并在parse中重新创建似乎可以解决问题。非常奇怪。将此代码用于swift 3.0
let installation = PFInstallation.current()
installation.setObject(Token, forKey: "deviceToken")
if(installation.badge != 0)
{
installation.badge = 0
}
installation.saveEventually()
哪一行出错?Setdevicetokenfromdata那一行我觉得这很奇怪,因为这不是objective C版本中所做的工作Anks ClareHuxtable,今晚我将再次讨论这一点,希望这能让它正常工作。其中“Token”是一个字符串值
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
//ENABLE PUSH NOTIFICATIONS
let userNotificationTypes = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound)
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return true
}
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
//Store the deviceToken in the current installation and save it to Parse.
let currentInstallation: PFInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.saveInBackground()
}
func application(application: UIApplication!, didReceiveRemoteNotification userInfo: NSDictionary!) {
PFPush.handlePush(userInfo)
}
let installation = PFInstallation.current()
installation.setObject(Token, forKey: "deviceToken")
if(installation.badge != 0)
{
installation.badge = 0
}
installation.saveEventually()