Search code examples
iosapple-push-notificationscloudkit

CloudKit CKSubscription Includes Mandatory Notifications?


I'm writing a CloudKit-based iOS and Mac application that uses a CKSubscription to get notified when an update occurs in the remote data set. I've got the subscription setup correctly and the notifications are being received. Everything works great! The only issue is that the device receives a user-facing notification.

User Facing Notification for CloudKit CKSubscription

I would prefer that the remote update notification be an application internal implementation detail; I don't want the user receiving a notification every time they update their own collection of objects. I can't seem to find anything to address this in the documentation. Apple's own docs here talk about this like "duh, of course you want to do a notification." Well, I don't.


Solution

  • If you leave the alertBody of the CKNotificationInfo blank, then you won't get a user facing notification. The notification will be received in your app where you can handle it as usual.

        var subscription = CKSubscription(recordType: recordType, predicate: predicate, options: .FiresOnRecordCreation | .FiresOnRecordUpdate | .FiresOnRecordDeletion)
        subscription.notificationInfo = CKNotificationInfo()
        subscription.notificationInfo.shouldSendContentAvailable = true
        subscription.notificationInfo.soundName = UILocalNotificationDefaultSoundName
        subscription.notificationInfo.alertBody = ""