【发布时间】:2020-03-28 05:20:24
【问题描述】:
我正在尝试在使用NSPersistentCloudKitContainer 的CoreData+CloudKit 项目中执行历史跟踪。我一直在关注苹果的sample project
我想在远程存储更新后执行某些任务。为此,苹果建议在应用程序的“签名和功能的后台模式”部分启用远程通知。
我已为我的项目启用历史跟踪,如 Apple 的示例项目所示。
// turn on persistent history tracking
let description = container.persistentStoreDescriptions.first
description?.setOption(true as NSNumber,
forKey: NSPersistentHistoryTrackingKey)
// ...
我还注册了我的商店以监听商店的变化。
// turn on remote change notifications
let remoteChangeKey = "NSPersistentStoreRemoteChangeNotificationOptionKey"
description?.setOption(true as NSNumber,
forKey: remoteChangeKey)
// ...
还添加了观察者来监听NSPersistentStoreRemoteChangeNotification。
但是没有NSPersistentStoreRemoteChangeNotification 被解雇。为了确保我的实现没有错误,我只是在@objc func storeRemoteChange(_ notification: Notification) Apple 提供的示例代码中放置了断点,但我仍然看不到任何通知被触发并且没有激活断点。
我已经了解示例项目中对标签的重复数据删除,也尝试过对其进行测试,但没有任何成功。这是 Apple 实施中的错误还是我缺少任何所需的设置?
【问题讨论】:
-
嗨,您最终找到解决方案了吗?我处于这种确切的情况,现在我只是依靠 automaticMergesChangesFromParent 让它为云+扩展更改做自己的事情。然后我在 willEnterForegroundNotification 上强制执行一个新的 fetchrequest。这是我能想到的唯一方法。这很糟糕吗?
标签: core-data cloudkit ios13 nspersistentcloudkitcontainer