我希望有人可以指导我...我知道 Swift 2.0/Xcode 7 仍处于测试阶段,但我需要转换我的代码... 这是我的代码...
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let notification:CKNotification = CKNotification(fromRemoteNotificationDictionary: userInfo)
//application.applicationIconBadgeNumber = 0
if (notification.notificationType == CKNotificationType.Query) {
let queryNotification = notification as! CKQueryNotification
let recordID = queryNotification.recordID
receivedRecord = recordID
NSNotificationCenter.defaultCenter().postNotificationName("updateDatabase", object: nil)
}
}
因此 CKNotification 的预期 Dict 已更改为 [String:NSObject] -> 之前是 [NSObject:AnyObject] ,与返回的 Dict 一致!从函数(didReceiveRemoteNotification)返回的 Dict 是: [NSObject : AnyObject]
取自 Xcode 7 -> 公共(public)便利 init(fromRemoteNotificationDictionary notificationDictionary: [String : NSObject])
取自 Xcode 6.4 -> 方便 init!(fromRemoteNotificationDictionary notificationDictionary: [NSObject : AnyObject]!)
所以,我的问题是,我该如何转换它,或者我是否错过了一些明显的东西?这可能是一个错误吗?
感谢您的指导/帮助...
最佳答案
这样做:
if let userInfo = userInfo as? [String: NSObject] {
let notification = CKNotification(fromRemoteNotificationDictionary: userInfo)
...
...
}
关于swift - RemoteNotification Dict 已更改,CKNotification Dict 现在不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32201646/