我试图从CloudKit获得静默推送。但它只适用于我的应用程序在前台(或者当它从Xcode启动时,在这种情况下通知也在后台传送)。
我已启用所有相应的背景模式。
在 didFinishLaunchingWithOptions
中注册了remoteNotifications和指定的背景fetchInterval UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
application.registerForRemoteNotifications()
我在这里没有问题 didRegisterForRemoteNotificationsWithDeviceToken 。
我已经实施了处理remoteNotifications的方法:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
NSLog(__FUNCTION__)
let identifier : UIBackgroundTaskIdentifier = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler(){
}
CoreDataStack.sharedInstance.ensemblesSynchronizeWithCompletion(){
UIApplication.sharedApplication().endBackgroundTask(identifier)
completionHandler(UIBackgroundFetchResult.NewData)
}
}
我尝试将CloudKit容器切换到Production并使用TestFlight进行测试。 结果总是一样的:在前台我得到了CKNotifications,但对于控制台中的后台,我看到了:
错误:apsd [81]:无声推送:拒绝应用无法使用
此外,我已经尝试过: 彻底更换容器 - 没有运气。
我也相应地编辑了我的AppID,但我不认为它对于CloudKit通知是必要的(或者是吗?):
从设备启动时的控制台输出(不是来自Xcode)
应用运行背景:
从Xcode启动时,我会在后台获取通知&前景。
答案 0 :(得分:0)
如果您强制退出应用程序,则iOS会停止在后台向您的应用发送推送通知。当您从Xcode运行应用程序并想要退出时,请确保从Xcode“停止”该过程,而不是从设备上的应用程序切换器向上滑动。
您可能只需重新启动手机即可获得无声推送通知以重新开始工作。