swift - RemoteNotification Dict 已更改,CKNotification Dict 现在不同

标签 swift apple-push-notifications cloudkit xcode7

我希望有人可以指导我...我知道 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/

相关文章:

ios - 如何自动清除文本字段

Swift 3 - 发送带有图像的消息 - 未确定的文字

android - 类似android的iOS应用程序未运行或关闭状态时如何处理数据类型fcm通知?

ios - 使用 CloudKit 延迟后触发推送通知

ios - TestFlight开发和生产

swift - 从 View Controller 调用函数 - 参数错误 - Swift2

xcode - 为什么我的 scrollView 是零?

ios - 您什么时候会在推送负载中使用 "thread-id" key ?

ios - XCUITest 与通知横幅交互。

ios - CloudKit 可以创建共享私有(private)容器吗?