Reputation: 55725
I'm building an app with Core Data and CloudKit. I need to detect when remote changes have been pushed to the app and are available in the local database to perform some work on the new data set. I've implemented .NSPersistentStoreRemoteChange
like so:
NotificationCenter.default.addObserver(self, selector: #selector(self.storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator)
The problem is this notification is received even when changes haven't been received from the remote CloudKit database, such as 4 times when the app is launched, and when a modification is made to the local database. How can I know only when changes have been received from the remote database?
Upvotes: 7
Views: 1133
Reputation: 30582
This was added in iOS 14
NSPersistentCloudKitContainer.eventChangedNotification NSPersistentCloudKitContainer.EventType.import
Upvotes: 1
Reputation: 55725
While I wasn't able to detect only this scenario, I did accomplish my needs by utilizing NSManagedObjectContextObjectsDidChangeNotification
and performing both remote and local change processing when this notification is triggered.
Upvotes: 1