我正在使用Core Data和CloudKit构建一个应用程序。我需要检测远程更改何时被推送到应用程序,并在本地数据库中可用,以便对新数据集执行一些工作。.NSPersistentStoreRemoteChange
是这样实现的:
NotificationCenter.default.addObserver(self, selector: #selector(self.storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator)
问题是,即使没有从远程CloudKit数据库收到更改,也会收到此通知,例如启动应用程序时收到4次,以及对本地数据库进行修改时。如何才能知道何时从远程数据库收到更改?
2条答案
按热度按时间gpnt7bae1#
虽然我不能只检测到这种情况,但我确实通过利用
NSManagedObjectContextObjectsDidChangeNotification
并在触发此通知时执行远程和本地更改处理来满足我的需求。lnxxn5zx2#
这是在iOS 14中添加的
NSPersistentCloudKitContainer.eventChangedNotificationNSPersistentCloudKitContainer.EventType.import