3

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
            }
        })
    }
rs7
  • 1,618
  • 1
  • 8
  • 16

1 Answers1

3

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.

rs7
  • 1,618
  • 1
  • 8
  • 16
  • Aaah that's why I was getting the NSUbiquitousKeyValueStore errors as well in the Catalyst version of my app. I didn't spend any time on it and just disabled the sync feature. – EarlGrey Feb 26 '20 at 21:28
  • @rs7 I used the new Xcode version to create macCatalyst target with the same bundle ID, but still can't receive remote notification from CloudKit - have you tried it and any way to make it work? – hyouuu Aug 13 '20 at 01:34
  • Just to add the application(_, didRegisterForRemoteNotificationsWithDeviceToken) gets called, but no notification on mac. Also cc @EarlGrey did you get any success? – hyouuu Aug 13 '20 at 01:35
  • If you can open a new thread for your question and add some more details (code for didreceive and didRegisterForRemoteNotification etc), I'll look into it. – rs7 Aug 14 '20 at 07:57
  • Thanks @rs7 - here is the question: https://stackoverflow.com/questions/63421613/ckquerynotification-not-received-on-maccatalyst-build – hyouuu Aug 15 '20 at 00:52