Question

I have been using iCloud in my apps for a while now and am recently having an issue where devices refuse to talk to each other. Or at least that's what I thought until I started logging the methods where the merging takes place. My persistentStoreCoordinator is set up as described in a previous question of mine.

The problem is the following. When setting up my managedObjectContext, I add an observer to it to view the NSPersistentStoreDidImportUbiquitousContentChangesNotification notification like follows:

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

where coordinator is the set up as NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator].

My iCloud methods are as follows:

- (void)mergeiCloudChanges:(NSNotification *)note forContext:(NSManagedObjectContext *)moc {
    NSLog(@"insert %@", [[note userInfo] valueForKey:@"inserted"]);
    NSLog(@"delete %@", [[note userInfo] valueForKey:@"deleted"]);
    NSLog(@"update %@", [[note userInfo] valueForKey:@"updated"]);
    [moc mergeChangesFromContextDidSaveNotification:note];

    NSNotification *refreshNotification = [NSNotification notificationWithName:@"RefreshAllViews" object:self userInfo:[note userInfo]];
    [[NSNotificationCenter defaultCenter] postNotification:refreshNotification];
}

- (void)mergeChangesFrom_iCloud:(NSNotification *)notification {
    NSLog(@"merging changes");
    NSManagedObjectContext *moc = [self managedObjectContext];
    [moc performBlock:^{
        [self mergeiCloudChanges:notification forContext:moc];
    }];
}

So now we have the actual problem

At first, syncing went flawlessly. Data from one device was changed, then that change appeared on the other device. But now, nothing. The curious part is in those logs you see in mergeiCloudChanges:forContext:. The merge actually occurs. I see this triggered. But the insert, delete, and update parts of the merge note are ALWAYS without content. So the merge occurs, but with no data. For the life of me, I cannot figure out why this is or how to get it to sync properly again. Any help would be more than appreciated.

Note: I am also using the NSUbiquitousKeyValueStoreDidChangeExternallyNotification notification for my NSUbiquitousKeyValueStore (which I use to sync the NSUserDefault key-values), and those notifications transfer over and update without any hiccups at all, which confuses me even more as to why the persistentStoreCoordinator notifications are blank.

I truly hope someone has seen/experienced this before because after two weeks exhausting every avenue I can think of to find and fix this on my own, I feel I am now at a standstill.

Was it helpful?

Solution

I've got this one figured out. Basically, the transaction logs appeared to be corrupted or misplaced. I have reworked a way to resycn devices and will be posting the results immediately on a previous question of mine

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top