当设备处于请勿打扰模式时(即使应用程序位于private和shared databases
>前景)。
当设备未处于请勿打扰模式时,我会在发生订阅时收到订阅更改。
注册远程通知:
application.registerForRemoteNotifications()
数据库订阅:
let subscription = CKDatabaseSubscription(subscriptionID: "Test")
let notificationInfo = CKNotificationInfo()
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo
接收通知:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let notification = CKNotification(fromRemoteNotificationDictionary: userInfo)
dataService.receivedCloudKitNotification(notification,
completionBlock: completionHandler)
}
由于我没有使用声音/徽章/警报/ carplay(UNAuthorizationOptions
),我选择了上述方法。