以下是我准备订阅的方式:

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

通知将永久显示在屏幕上。
ios - 如何防止在屏幕上通知用户有关CloudKit中的新更改?-LMLPHP
我真的不想在这里。如果应用程序处于活动状态,但在应用程序未运行或处于前台模式时不显示任何内容,是否有方法传递通知?

最佳答案

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

10-08 01:05