这就是我准备订阅的方式:
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 }
}
并且会在屏幕上永久显示通知。
我真的不想在这里。有没有办法在应用程序处于活动状态时发送通知,但在应用程序未运行或处于前台模式时不显示任何内容?
答案 0 :(得分:1)
您需要正确设置通知信息。不要设置alertLocalizationKey
。 shouldSendContentAvailable
应设置为true
。
答案 1 :(得分:1)
尝试此代码,这不会显示通知横幅
let notificationInfo = CKNotificationInfo()
notificationInfo.shouldBadge = false
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo