Skip to content


MR_mergeChangesFromiCloud not called #169

andr8w opened this Issue · 1 comment

2 participants


I started experimenting with iCloud support in MagicalRecord just recently before v2. The merge notification was being called. After updating to v2, the notification is called intermittently.

The notification is setup in MR_setDefaultContext:

+ (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
    NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
    if ([MagicalRecord isICloudEnabled]) 
        [defaultManagedObjectContext_ MR_stopObservingiCloudChangesInCoordinator:coordinator];

    defaultManagedObjectContext_ = moc;

    if ([MagicalRecord isICloudEnabled]) 
        [defaultManagedObjectContext_ MR_observeiCloudChangesInCoordinator:coordinator];

If isICloudEnabled is NO at this point, the notifications are not setup.

iCloudEnabled is set inside a dispatch_async block from MR_addiCloudContainerID.

It seems that if the async block is executed after MR_setDefaultContext is called, then iCloudEnabled is NO and the notification is not setup.

If the following code is executed before the dispatch_async block, then the notifications are posted.

NSURL *cloudURL = [NSPersistentStore MR_cloudURLForUbiqutiousContainer:containerID];
if (subPathComponent) 
    cloudURL = [cloudURL URLByAppendingPathComponent:subPathComponent];

[MagicalRecord setICloudEnabled:cloudURL != nil];

URLForUbiquityContainerIdentifier must be called on a background thread, as MagicalRecord currently does. If this is the issue, what would be a better solution?



Given the age of this issue, and the volume of issues we have to work through, I've decided to close this alongside a number of other older issues.

If you can still replicate the issue under the latest in-development version of MagicalRecord (3.0 at the time of writing), please feel free to re-open and one of @magicalpanda/team-magicalrecord will take another look. Thanks!

@tonyarnold tonyarnold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.