Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:45:42+00:00 2026-06-12T17:45:42+00:00

I am trying to get iCloud to work with my app, which needs to

  • 0

I am trying to get iCloud to work with my app, which needs to migrate an existing local store to a ubiquitous store, if the user requests it.

After some nosing around Apple dev forums and elsewhere, I have taken this approach, which is not working consistently. I have actually seen it work, but only after several crashes on Device B (which is populated from iCloud).

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  if (persistentStoreCoordinator != nil)
    return persistentStoreCoordinator;

  NSURL *legacyStoreUrl = [NSURL fileURLWithPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:[self activeStoreFilenameUpgraded:NO]]];
  NSURL *upgradedStoreUrl = [NSURL fileURLWithPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:[self activeStoreFilenameUpgraded:YES]]];

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

  if ((IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0")) && (self.iCloudEnabled)) {
    NSPersistentStoreCoordinator* psc = persistentStoreCoordinator;

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSDictionary *cloudOptions = nil;
    NSDictionary *localOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                    [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                                    nil];


    NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:@"<CONTAINER ID>"];
    NSString *coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:[NSString stringWithFormat:@"logs%d",[self activeStoreIndex]]];
    if ([coreDataCloudContent length] != 0) {
        // iCloud is available
        cloudURL = [NSURL fileURLWithPath:coreDataCloudContent];

        cloudOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                       [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                       [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                       @"MyAppStore", NSPersistentStoreUbiquitousContentNameKey,
                       cloudURL, NSPersistentStoreUbiquitousContentURLKey,
                       nil];
    } else {
        // iCloud is not available
    }

    NSError *error = nil;
    [psc lock];
    if(migrateStore) {
        migrateStore = NO;

        NSPersistentStore *srcPS = [psc addPersistentStoreWithType:NSSQLiteStoreType
            configuration:nil
            URL:legacyStoreUrl
            options:localOptions
            error:&error];
        if (![psc migratePersistentStore:srcPS
            toURL:upgradedStoreUrl
            options:cloudOptions
            withType:NSSQLiteStoreType
            error:&error]) {
            NSLog(@"Error migrating data: %@, %@ / %@ / %@", error, [error userInfo], legacyStoreUrl, upgradedStoreUrl);
            abort();
        }
    }
    else {
        if (![psc addPersistentStoreWithType:NSSQLiteStoreType
            configuration:nil
            URL:upgradedStoreUrl
            options:(cloudOptions ? cloudOptions : localOptions)
            error:&error]) {
              NSLog(@"Unresolved iCloud error %@, %@", error, [error userInfo]);
              abort();
        }
    }
    [psc unlock];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"RefetchAllDatabaseData" object:self userInfo:nil];
  } else {
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                             nil];

    NSError *error = nil;
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:legacyStoreUrl options:options error:&error]) {
        // error
        abort();
    }    
  }

  return persistentStoreCoordinator;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:45:43+00:00Added an answer on June 12, 2026 at 5:45 pm

    iCloud Core Data syncing is terribly broken. A more reliable third-party solution is TICoreDataSync; this fork has support for syncing over iCloud, without relying on iCloud’s Core Data sync implementation. It simply uses iCloud to sync files and handles the Core Data object syncing on its own.

    I gave up on iCloud Core Data syncing and have been building my app with this library instead; so far it’s been working great, with none of the issues I saw with Apple’s implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get an iCloud-enabled app into the App store. The actual
Hi I am trying to get my core data app syncing to iCloud so
I'm trying to get a list of directories in the user's iCloud folder. I
I am trying get Javascript popup calendar control to work which doesnt work. I
So i am trying get 2 div-containers which both should contain centered text (Both
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
I have a Mac app I have written to support iCloud. However, I get
I'm trying get LocalConnection to work between two swf's placed within two different IFRAMES.
I'm trying get my <a> tag triggered when the user press on the enter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.