So, it finally happened. The worst case scenario for any independent iPhone developer occurred. Several users are reporting complete data loss 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 catastrophic failure.
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.
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.
What could be the reason for this?
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.
- (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_; }
and
- (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:&error]) { NSLog(@"Cannot create persistent store coordinator, %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator_; }
Comments, opinions, wild guesses etc. (and of course solutions!) are all welcome.
UPDATE:
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.
Things you can try to speed up iCloud:Confirm that your iPhone is set up to connect to the same Wi-Fi network as your Mac. Now have your iPhone and Mac next to each other, both using the same Wi-Fi network (make sure they both can connect to the Internet) Optional: connect your iPhone to your Mac using its cable.
It backs up automatically in the middle of the night, every night. Also, you have to be sure you have enough space in iCloud for your backup.
Sign out of your Apple ID, and iCloud, then restart your device and try syncing again. My favorite troubleshooting tip is to restart the problematic device. Since you can't reach into Apple's servers and restart iCloud, the next best thing is to sign out on all your devices, then sign back in again.
I was facing something similar with few uses ( by your description I assumed you have way more volume than I do, that's might the reason for several cases )
In my case Apple seemed to have removed without earlier notice the 20gb free space in the icloud. I noticed that the 2 uses who are power data usage users had lost of new data from my app (which was to deal with historical stock pricing ) and the others ones we just fine downloading the same data size.
I followed up with those 2, helping them to clean stuff up to let more space in icloud and voila, after downloading the data again it worked fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With