UbiquityStoreManager icon indicating copy to clipboard operation
UbiquityStoreManager copied to clipboard

Migrating the local cloud store within the `...willLoadStoreIsCloud:` method?

Open NorbNorb opened this issue 10 years ago • 0 comments

I'd like to check if an app update brought a new Core Data model version. If so, I'd like to migrate the cloud data, disable iCloud and work offline then. In particular:

  1. manually migrate the cloud store in ubiquityStoreManager:willLoadStoreIsCloud: to the new model version
  2. migrateCloudToLocal
  3. setCloudEnabled = NO (step 2 does this already automatically)

or in code:

- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager willLoadStoreIsCloud:(BOOL)isCloudStore
{
  if (isCloudStore)
    {
        NSURL *cloudStoreURL = manager.URLForCloudStore;  // WRONG: gives ubiquity directory, not an sql file
        if ([self isMigrationNeededForSourceStoreURL:cloudStoreURL])
        {
            [self migrateStoreToCurrentModel:cloudStoreURL];
            [manager migrateCloudToLocal]; // This will also set iCloud disabled
        }
    }
}

My problem is that I cannot do the manual migration without knowing the URL to the persistent store file (sqlite). When ubiquityStoreManager:willLoadStoreIsCloud: is called there's no store coordinator which can tell me where the file is or which cloud store file to use. Also, can I call migrateCloudToLocal within ubiquityStoreManager:willLoadStoreIsCloud:?

NorbNorb avatar Aug 15 '14 13:08 NorbNorb