首页 > 解决方案 > 如何在仅从远程 CloudKit 数据库收到更改时收到通知?

问题描述

我正在使用 Core Data 和 CloudKit 构建一个应用程序。我需要检测远程更改何时被推送到应用程序并且在本地数据库中可用以对新数据集执行一些工作。我已经.NSPersistentStoreRemoteChange这样实现了:

NotificationCenter.default.addObserver(self, selector: #selector(self.storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator)

问题是即使没有从远程 CloudKit 数据库收到更改也会收到此通知,例如启动应用程序 4 次,以及对本地数据库进行修改时。我如何才能知道何时从远程数据库收到更改?

标签: ioscore-datacloudkit

解决方案


虽然我无法仅检测到这种情况,但我确实通过NSManagedObjectContextObjectsDidChangeNotification在触发此通知时利用并执行远程和本地更改处理来满足我的需求。


推荐阅读