以下是我准备订阅的方式:
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 }
}
通知将永久显示在屏幕上。
我真的不想在这里。如果应用程序处于活动状态,但在应用程序未运行或处于前台模式时不显示任何内容,是否有方法传递通知?
最佳答案
您需要正确设置通知信息。不要设置alertLocalizationKey
。shouldSendContentAvailable
应设置为true
。