Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didReceiveRemoteNotification not being called on MacCatalyst

When I create a CKSubscription, didReceiveRemoteNotification gets called on iOS just fine but not on MacOS. I came across a 2015 SO thread talking about a bug and the suggested workaround was to set the notification info's soundName to an empty string - unfortunately that didn't resolve the issue for me.

Here is how I register my remote notifications:

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

        let subscription = CKQuerySubscription(recordType: "Reminder", 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 = ""

        subscription.notificationInfo = info

        // Save the subscription to Private Database in Cloudkit
        CKContainer.default().privateCloudDatabase.save(subscription, completionHandler: { subscription, error in
            if error == nil {
                // Subscription saved successfully 
            } else {
                // Error occurred
            }
        })
    }
like image 974
rs7 Avatar asked Oct 16 '25 15:10

rs7


1 Answers

This has to do with the bundle identifier being different on Mac Catalyst. Thanks to the soon to be introduced universal app purchase, catalyst apps can now bear the same bundle identifier as their iOS counterpart, and that fixes the issue.

Note that I was also experiencing issues with cloudkit key values not syncing on Mac (NSUbiquitousKeyValueStore). Having a single bundle id for Mac and iOS fixed the problem too.

like image 94
rs7 Avatar answered Oct 19 '25 04:10

rs7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!