1

I'm having some weird issues with iCloud and Core Data syncing across devices. The problem is that records are syncing sporadically and certain notifications are blank.

For example, if I add three records to the database, only two of the three records will sync. Same thing for deletions. However, when I rebuild the data store from scratch (NSPersistentStoreRebuildFromUbiquitousContentOption), all the correct entries are present. As you can see in the log file below, I think the issue is that the Notifications are not populating correctly. The middle change should be a deletion but nothing is populated.

See below a copy of the logs and the code I am using for mergeChangesFromContextDidSaveNotification.

Logs:

  • 2015-05-02 00:05:42.339 Tracker[1370:219748] persistentStoreDidImportUbiquitousContentChanges
  • 2015-05-02 00:05:42.339 Tracker[1370:219748] NSConcreteNotification 0x17485dbe0 {name = com.apple.coredata.ubiquity.importer.didfinishimport; object = ; userInfo = { deleted = "{(\n 0xd00000002fe40000 \n)}"; inserted = "{(\n)}"; updated = "{(\n)}"; }}
  • 2015-05-02 00:05:42.341 Tracker[1370:219748] Underlying data changed ... refreshing!
  • 2015-05-02 00:05:44.293 Tracker[1370:219748] persistentStoreDidImportUbiquitousContentChanges
  • 2015-05-02 00:05:44.293 Tracker[1370:219748] NSConcreteNotification 0x170a498a0 {name = com.apple.coredata.ubiquity.importer.didfinishimport; object = ; userInfo = { deleted = "{(\n)}"; [SHOULD BE A DELETION BUT NOTHING] inserted = "{(\n)}"; updated = "{(\n)}"; }}
  • 2015-05-02 00:05:44.308 Tracker[1370:219748] Underlying data changed ... refreshing!
  • 2015-05-02 00:05:46.266 Tracker[1370:219748] persistentStoreDidImportUbiquitousContentChanges
  • 2015-05-02 00:05:46.266 Tracker[1370:219748] NSConcreteNotification 0x174a5c0b0 {name = com.apple.coredata.ubiquity.importer.didfinishimport; object = ; userInfo = { deleted = "{(\n 0xd00000002fe00000 \n)}"; inserted = "{(\n)}"; updated = "{(\n)}"; }}
  • 2015-05-02 00:05:46.292 Tracker[1370:219748] Underlying data changed ... refreshing!

Code:

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserverForName:NSPersistentStoreDidImportUbiquitousContentChangesNotification
                                    object:self.persistentStoreCoordinator
                                     queue:[NSOperationQueue mainQueue]
                                usingBlock:^(NSNotification *note) {

                                    NSLog(@"persistentStoreDidImportUbiquitousContentChanges");
                                    NSLog(@"%@", note);

                                    [self.managedObjectContext performBlock:^{
                                        [self.managedObjectContext mergeChangesFromContextDidSaveNotification:note];

                                        NSNotification* refreshNotification =
                                            [NSNotification notificationWithName:@"iCloudReloadTable"
                                                                          object:self
                                                                        userInfo:[note userInfo]];

                                            [[NSNotificationCenter defaultCenter] postNotification:refreshNotification];
                                    }];
                                }];
Doug
  • 106
  • 2
  • 8
  • FYI - I filed a Technical Support Incident with Apple on this. The Apple Engineer sent me sample code, which had the exact same issue present. The Engineer told me to file a bug report, which is still outstanding and unresolved. The only solution I have come up with is not using iCloud and Core Data syncing. – Doug Jul 27 '15 at 16:00
  • I'm getting a similar issue. In my case a notification that should contain changes - but does not. None of the notifications on iOS contain details. They do back on macOS. persistentStoreDidImportUbiquitousContentChanges: NSConcreteNotification 0x170c5b150 {name = com.apple.coredata.ubiquity.importer.didfinishimport; object = ; userInfo = { deleted = "{(\n)}"; inserted = "{(\n)}"; updated = "{(\n)}"; – David Wilson Dec 04 '16 at 00:29
  • Did anything ever come from your bug report? – David Wilson Dec 04 '16 at 00:31
  • Nothing. I double-checked the bug report I filed on 5/10/15 and the report is still open. As I mentioned, I've abandoned Core Data syncing entirely. I'm now using iCloud Documents syncing instead. – Doug Dec 05 '16 at 04:53
  • Dam. Appreciate you looking up the bug report. Thanks Doug. – David Wilson Dec 07 '16 at 08:38

0 Answers0