Automatic easy migration works for local storage, but iCloud storage "loses" all outdated data

I rip off my hair with this. I have an application in iTunes that I added to iCloud before the end of last year (October '13) on iOS7.0. This week I decided to write new functionality for an application that requires a new object in xcdatamodel. Very simple change / add. Should not affect the current data set. I create a new v2 xcdatamodel and install it in the version of the current model, compile and run, and it works fine if iCloud is disabled on my iPad. I see the previous saved data. Run it again with iCloud enabled, and I will get an empty table without data. No error messages, nothing. Hoping someone can shed light on what I did wrong:

- (NSManagedObjectModel *)managedObjectModel { if (__managedObjectModel != nil) { return __managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UserData" withExtension:@"momd"]; __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return __managedObjectModel; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { NSError *error = nil; BOOL success = NO; if((__persistentStoreCoordinator != nil)) { return __persistentStoreCoordinator; } __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; NSPersistentStoreCoordinator *psc = __persistentStoreCoordinator; NSString *iCloudEnabledAppID = @"C3FUPX46ZG~com~software~App"; NSString *dataFileName = @"UserData.sqlite"; NSString *iCloudDataDirectoryName = @"CoreData.nosync"; NSString *iCloudLogsDirectoryName = @"CoreDataLogs"; NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *localStore = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:dataFileName]; NSURL *iCloud = [fileManager URLForUbiquityContainerIdentifier:nil]; if (iCloud && ([UserDefaults getIsiCloudOn])) { // This iCloud storage fails to migrate. NSURL *iCloudLogsPath = [NSURL fileURLWithPath:[[iCloud path] stringByAppendingPathComponent:iCloudLogsDirectoryName]]; if([fileManager fileExistsAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName]] == NO) { NSError *fileSystemError; [fileManager createDirectoryAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName] withIntermediateDirectories:YES attributes:nil error:&fileSystemError]; if(fileSystemError != nil) { NSLog(@"Error creating database directory %@", fileSystemError); } } NSString *iCloudData = [[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName] stringByAppendingPathComponent:dataFileName]; NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES, NSPersistentStoreUbiquitousContentNameKey : iCloudEnabledAppID, NSPersistentStoreUbiquitousContentURLKey : iCloudLogsPath }; success = [psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:iCloudData] options:options error:&error]; if (!success) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } } else { // This local storage migrates automatically just fine. NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES }; success = [psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:localStore options:options error:&error]; if (!success) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } } dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:kCoreDataChangeNotification object:self userInfo:nil]; }); return __persistentStoreCoordinator; } 

UPDATE: Switches to debugging master data and debugging and logging iCloud. Migration works both locally and iCloud. Logs match, ending in:

CoreData: annotation: (migration) displaying a mapping model between data models using ... CoreData: annotation: (migration) in-place migration completed successfully in 0.03 seconds -PFUbiquitySwitchboardEntryMetadata setUseLocalStorage :: CoreData: Ubiquity: mobile ~ F9AC6EB1 Using local storage : one

With iCloud storing and debugging on it, it seems to cause a delay, and I briefly see my saved data for about 10 seconds when it disappears. Just before it disappears, debugs spit out:

CoreData: annotation: (migration) mapping model output between data models using ... Using local storage: 0

ICloud magazines are huge, so I do not post them here. From what I see, I have over 400 log files, and iCloud seems to be doing some sort of synchronization. If I leave the App and iPad open and turned on for several hours, I still see an empty dataset. So this is not a case of waiting for synchronization. I'm still at a loss even with debuggers ....

+7
ios7 core-data icloud core-data-migration
source share

No one has answered this question yet.

See related questions:

63
IPhone Master Data Auto Easy Migration
4
iCloud Core Data Lightweight Migration - Entities Disappear
3
Migrating the primary database - "Cannot add source storage" error
3
iPhone Core Data Lightweight Migration: Unable to merge models
2
Converting an attribute from NSNumber to NSString in a CoreData object - LightWeightMigration
2
Key Data Easy Migration - Merge Models
one
iCloud and easy migration
one
problems with CoreData migrations in RubyMotion
0
Automatic easy migration of master data - transition from unversioned to version data model
0
I can not find a model for the source store iOS 12

All Articles