Note that there are some explanatory texts on larger screens.

plurals
  1. POMore iCloud Core Data synching woes
    primarykey
    data
    text
    <p>So, it finally happened. The worst case scenario for any independent iPhone developer occurred. Several users are reporting complete <strong>data loss</strong> after upgrading my app. iCloud Core Data sync is not working. My users are using this app partially to run their businesses. This is a truly <em>catastrophic failure</em>.</p> <p>The only iCloud related thing I changed was to add the key-value store to iCloud. The core data code remained exactly the same, same model version (no migration) etc.</p> <p>In my tests everything worked beautifully! But to my dismay, users reported that their data was not there anymore when they opened the updated app. </p> <p>What could be the reason for this? </p> <ul> <li>The <em>persistent store URL</em> (an ubiquitous URL) should not have changed. </li> <li><em>Merge conflicts</em> are also unlikely, as this problem should have arisen before the update.</li> <li><strike>Some interference with the new <em>ubiquitous key-value store</em> perhaps?</strike><br> (I have pretty much ruled this out.)</li> </ul> <p>Below please find the code for my managed object model and persistent store. Let me know if you need anything else to assess the problem. </p> <pre><code>- (NSManagedObjectContext *)managedObjectContext { if (managedObjectContext_ != nil) { return managedObjectContext_; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { managedObjectContext_ = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [managedObjectContext_ performBlockAndWait:^{ [managedObjectContext_ setPersistentStoreCoordinator:coordinator]; if (useICloud) { [managedObjectContext_ setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mergeiCloud:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:coordinator]; } }]; } return managedObjectContext_; } </code></pre> <p>and </p> <pre><code>- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator_ != nil) { return persistentStoreCoordinator_; } NSMutableDictionary *options = [NSMutableDictionary dictionary]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"SalesCalls.sqlite"]; [options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption]; [options setObject:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption]; if (useICloud) { // this is an internal flag set to YES NSURL *iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; if (nil!=iCloudURL) { NSString *cloudData = [[iCloudURL path] stringByAppendingPathComponent:@"data"]; iCloudURL = [NSURL fileURLWithPath:cloudData]; [options setObject:@"at.topofmind.salesplus.store" forKey:NSPersistentStoreUbiquitousContentNameKey]; [options setObject:iCloudURL forKey:NSPersistentStoreUbiquitousContentURLKey]; NSURL *nosyncDir = [iCloudURL URLByAppendingPathComponent:@"data.nosync"]; [[NSFileManager defaultManager] createDirectoryAtURL:nosyncDir withIntermediateDirectories:YES attributes:nil error:nil]; storeURL = [nosyncDir URLByAppendingPathComponent:@"SalesCalls.sqlite"]; } } NSError *error = nil; persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&amp;error]) { NSLog(@"Cannot create persistent store coordinator, %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator_; } </code></pre> <p>Comments, opinions, wild guesses etc. (and of course solutions!) are all welcome. </p> <p><strong>UPDATE:</strong> </p> <p>One of my customers lost all his data and after reinstalling and resetting everything (rebooting device, etc.) he could not sync with iCloud any more. The symbol simply does not show up in the Settings.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload