I process both private and shared database notifications by converting userInfo to CKDatabaseNotification. But I do get public database notifications also in didReceiveRemoteNotification method and Apple template code does not show how to process it and it raises a fatalError. How can I process public database notifications via my fetchChanges method?
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let dict = userInfo as! [String: NSObject]
guard let vc = self.window?.rootViewController as? UIViewController else { return }
guard let notification:CKDatabaseNotification = CKNotification(fromRemoteNotificationDictionary:dict) as? CKDatabaseNotification else { return }
self.fetchChanges(in: notification.databaseScope) {
completionHandler(UIBackgroundFetchResult.newData)
}
}
func fetchChanges(in databaseScope: CKDatabaseScope, completion: @escaping () -> Void) {
switch databaseScope {
case .private:
self.fetchPrivateChanges(completion: completion)
case .shared:
self.fetchSharedChanges(completion:) { status in
if (status == false) {
return
}
}
case .public:
fatalError()
}
}