如何防止在屏幕上通知用户有关CloudKit的新变化?

时间:2016-11-07 16:14:21

标签: ios swift cloudkit

这就是我准备订阅的方式:

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 }
}

并且会在屏幕上永久显示通知。

enter image description here

我真的不想在这里。有没有办法在应用程序处于活动状态时发送通知,但在应用程序未运行或处于前台模式时不显示任何内容?

2 个答案:

答案 0 :(得分:1)

您需要正确设置通知信息。不要设置alertLocalizationKeyshouldSendContentAvailable应设置为true

答案 1 :(得分:1)

尝试此代码,这不会显示通知横幅

let notificationInfo = CKNotificationInfo()
notificationInfo.shouldBadge = false
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo