1
votes

My app receives CKQueryNotification from CKQuerySubscription normally on iOS or iPadOS, but with MacCatalyst with the same bundle ID (generated from Xcode 11.6), it never receives CKQueryNotification even tho

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)

gets called properly upon app launch - whenever there's a record change on CloudKit, the method

func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Swift.Void)

never fires on the MacCatalyst build, whereas it fires immediately on iOS.

Any ideas why? There's a thread on Apple forum but don't see a solution yet: https://developer.apple.com/forums/thread/125069

2

2 Answers

1
votes

For anyone also experiencing this problem while developing your app, I decided to publish the app anyways and found out that in the App Store version, on Mac the catalyst app actually could get the notification almost immediately. So it seems to be a debug environment bug for CloudKit.

0
votes

You are not sharing enough code for us to help you, so I'll take a guess. Try to define your notificationInfo values as follows and see if that makes a difference. Inside didRegisterForRemoteNotifications:

    // This is your subscription object
    let subscription = CKQuerySubscription(recordType: "Subscription", predicate: NSPredicate(format: "TRUEPREDICATE"), options: [.firesOnRecordCreation, .firesOnRecordUpdate])
    
    // Here we customize the notification message
    let info = CKSubscription.NotificationInfo()

    info.shouldSendContentAvailable = true
    info.desiredKeys = ["identifier", "title", "date"]
    info.soundName = ""
    info.alertBody = ""
    info.title = ""
    info.alertActionLocalizationKey = ""

    // Assign the notification info to your subscription
    subscription.notificationInfo = info