I am providing an answer here to my question because it's clearer than updating the question and after a lot of debugging, I have this working, to some extent.
With debugging the addPersistentStore
and migratePersistentStore
lines of code, I came up with:
NSPersistentStore *localStore = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error];
NSLog(@"The localStore is %@", localStore);
NSPersistentStore *migratedStore = [_persistentStoreCoordinator migratePersistentStore:localStore toURL:[self iCloudURL] options:[self iCloudStoreOptions] withType:NSSQLiteStoreType error:&error];
NSLog(@"The migrationStore is %@", migratedStore);
The NSLog value of localStore is: The localStore is <NSSQLCore: 0x13451b100> (URL: file:///var/mobile/Applications/DDB71522-C61D-41FC-97C7-ED915D6C46A4/Documents/Planner.sqlite)
The NSLog value of migratedStore is: (null)
With debugging, I could see essentially the same thing, that migrateStore was always null.
I changed the code slightly:
NSPersistentStore *migratedStore = [_persistentStoreCoordinator migratePersistentStore:localStore toURL:storeURL options:[self iCloudStoreOptions] withType:NSSQLiteStoreType error:&error];
For the URL to be the storeURL and suddenly, everything started working, where storeURL:
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Planner.sqlite"];
My outputs were:
The localStore is <NSSQLCore: 0x14ee09b50> (URL: file:///var/mobile/Applications/CC0F7DA0-251F-46D6-8E43-39D63062AED2/Documents/Planner.sqlite)
[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](771): CoreData: Ubiquity: mobile~5BD59259-7758-42FB-986F-DDD173F75ED3:EnStor
The migrationStore is <NSSQLCore: 0x157e260b0> (URL: file:///var/mobile/Applications/A08D183D-ECD4-4E72-BA64-D21727DE7A3E/Documents/CoreDataUbiquitySupport/mobile~CB6C3699-8BF1-47DB-9786-14BCE1CD570A/EnStor/771D2B0B-870A-428E-A9A8-5DAE1295AF53/store/Planner.sqlite)
The Using Local Store went from 1 to 0 and my data from the App Store version of the app continued to be there through the migration to the new version. This was the output the first time I ran the app after the upgrade.
This is great news.
Every subsequent time I ran the app though, the data continued to migrate and so I would end up with duplicate results.
The issue also is the fact that when adding a new device, it doesn't pull down the information to the new device.
I don't quite understand why using storeURL as the url for migratePersistentStore worked?
I also don't want each new device to basically add a new persistent store if one already exists and I don't know how I would get around this and also I don't want the migration to occur again and again. It should only occur the one time.
I'm getting there, but still a lot of work to be done!