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.
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?
You need to setup the notification info properly. Don't set alertLocalizationKey
. shouldSendContentAvailable
should be set to true
.