1

I am working on Core Data syncing over iCloud between two Mac applications. I have it mostly working (based on http://timroadley.com/2012/04/03/core-data-in-icloud/) - data is being synced, but I'm never getting the content change notification I need to merge the changes into my local context.

In my AppDelegate's managedObjectContext method:

NSManagedObjectContext * moc = [[NSManagedObjectContext alloc] 
  initWithConcurrencyType:NSMainQueueConcurrencyType];

[moc performBlockAndWait:
^{

  [moc setPersistentStoreCoordinator:coordinator];
  [[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(mergeChangesFrom_iCloud:) 
    name:NSPersistentStoreDidImportUbiquitousContentChangesNotification 
    object:coordinator];

}];

My observer function never gets called:

- (void) mergeChangesFrom_iCloud:(NSNotification*) notification
{
  NSLog(@"Merging changes from iCloud");
  // everything past here is irrelevent - this log message never appears

The data store is most certainly being synced - deleting a record in app A and forcing a table reload in app B results in a Core Data fault failure as expected for unmerged changes. Quitting and restarting app B shows the correctly updated data.

A breakpoint on the addObserver call shows it is being called. A breakpoint in mergeChangesFrom_iCloud shows that it is not.

Why is the coordinator apparently never sending the NSPersistentStoreDidImportUbiquitousContentChangesNotification as the documentation (and tutorials) claim it should? Where can I begin debugging this?

Update

The mystery deepens. Using the Core Foundation function shown here - NSNotificationCenter trapping and tracing all NSNotifications - I do not see NSPersistentStoreDidImportUbiquitousContentChangesNotification appear at all among the mass of notifications flying by.

It looks like it's not being posted at all - nor do I see any other Core Data related notifications after the initial load happens on startup.

Community
  • 1
  • 1
Xtapolapocetl
  • 613
  • 5
  • 21
  • Did you find a sollution? I think I have a similar issue that devices not update without a forced quit and restart. I think this happens when the App is in background when a notification comes (in my case) but doesn't check for updates when opened again when loaded. – Luuk D. Jansen Jul 08 '12 at 19:16
  • No, I never found a solution to this - I believe iCloud syncing just doesn't work properly between two Mac applications on the same machine. Hopefully it will be fixed in the future. – Xtapolapocetl Jul 08 '12 at 22:52
  • do you see that your ubiquitous store is updated at all? does it differ between the two apps? (the URL I mean). – Magnus Jul 23 '12 at 13:13
  • No, the ubiquitous store doesn't get updated. The URLs are different - they are not dirctly sharing a Core Data store. Although it's worth mentioning that I gave up on this approach not long after this question, so something may have changed in a recent update. – Xtapolapocetl Jul 23 '12 at 18:15

0 Answers0