Search code examples
iosswiftcloudkit

How to prevent from notifying user on the screen about new change in CloudKit?


This is how I prepare subscription:

class func saveSubscriptions() {

    let options: CKSubscriptionOptions = [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion]
    let serviceSubscription = CKSubscription(recordType: "Service", predicate: NSPredicate(value: true), options: options)
    
    let notificationInfo = CKNotificationInfo()
    notificationInfo.alertLocalizationKey = "s"
    notificationInfo.shouldBadge = false
    notificationInfo.shouldSendContentAvailable = false

    serviceSubscription.notificationInfo = notificationInfo

    CloudContainer.publicCloudDatabase.save(serviceSubscription) { _, _ in }
}

and notification appears on the screen permanently.

enter image description here

I really do not want this here. Is there a way to deliver the notification if app is active but to not display anything while the app is not running or is in the foreground mode?


Solution

  • You need to setup the notification info properly. Don't set alertLocalizationKey. shouldSendContentAvailable should be set to true.