推送通知没有被发送(或接收)到我正在使用CloudKit订阅的应用程序,因为有很多方法可以向南,我将在下面列出我的'已完成,这可能会帮助其他人有相同的问题,并(希望)会指出我做错了:(Cloudkit没有发送推送通知
具体而言,我试图得到一个安静的通知记录插入(在后台
项目设置我在功能下启用CloudKit,在仪表板中设置记录类型,在功能下启用应用程序的推送通知,并且启用背景模式“remote-notific通货膨胀”。
注册在启动远程通知:
// Register for push notification
let settings = UIUserNotificationSettings(forTypes: [.Alert,.Badge,.Sound], categories: nil)
application.registerUserNotificationSettings(settings)
// Register for remote notification
application.registerForRemoteNotifications()
倾听推送通知注册成功(成功),并创建订阅:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
NSLog("Remote notifications registered - %@",deviceToken)
createSubscriptions()
}
创建我的订阅对象,设置它的通知信息,并将其保存到服务器:
private func createSubscriptions(user : CKRecord, completion: (NSError?) ->()) {
let messageSubscription = CKSubscription(recordType: "Messages", predicate: NSPredicate(format:"TRUEPREDICATE"), subscriptionID: "Messages", options: .FiresOnRecordCreation)
let notificationInfo = CKNotificationInfo()
notificationInfo.shouldSendContentAvailable = true
notificationInfo.soundName = ""
messageSubscription.notificationInfo = notificationInfo
CKContainer.defaultContainer().publicCloudDatabase.saveSubscription(subscription) { (_, error) in
if let error = error {
if error.domain == "CKErrorDomain" && error.code == 15 {
NSLog("Already set, ignoring dupe")
}
else
{
completion(error)
return
}
}
completion(nil)
}
}
我可以请参阅CloudKit Dashboard中的订阅确实已成功创建。
我然后创建一个从第二设备或仪表板的一些记录(“信息”),看到他们无论是在查询或仪表板调用添加,但该方法我已经得到通知没有被调用:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Crickets. Never called
}
我知道通知不能在模拟器上工作。我已经在使用设备的开发中尝试了这一点,并且在使用testflight和一些设备的生产环境中尝试了这一点。我是否错过了osmething?
我正在注册,删除并重新创建修复它的订阅,但只是在我更改了我使用的订阅标识符后。哎呀.. – BadPirate