ios - 如何防止在屏幕上通知用户有关 CloudKit 的新更改?

标签 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

我真的不想在这里。有没有一种方法可以在应用处于事件状态时发送通知,但在应用未运行或处于前台模式时不显示任何内容?

最佳答案

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

关于ios - 如何防止在屏幕上通知用户有关 CloudKit 的新更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40469676/

相关文章:

ios - Swift MapView -> 以编程方式启动 "didSelectAnnotation"与用手指点击注释不同

swift - 在 swift3 中处理 URL 的 Try Catch

ios - 如何使用 Swift 更改 UITableviewController 静态单元格部分背景颜色更改?

ios - 为什么我的 UI 按钮在经过一定时间后停止响应?

ios - 位置管理器 :didRangeBeacons not detect the same beacon two times

swift - 为什么 CloudKit 不允许我将任何记录保存到默认容器的公共(public)数据库中?

production - 在 CloudKit 中将记录从开发移动到生产

ios - 使用游标加载 UICollectionView

ios - 如何正确调整 TableView 单元格的大小?

ios - 了解如何从 IB 初始化自定义 UIView