Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More iCloud Core Data synching woes

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?

  • The persistent store URL (an ubiquitous URL) should not have changed.
  • Merge conflicts are also unlikely, as this problem should have arisen before the update.
  • Some interference with the new ubiquitous key-value store perhaps?
    (I have pretty much ruled this out.)

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.

like image 849
Mundi Avatar asked Jan 23 '13 11:01

Mundi


People also ask

How can I get iCloud to sync faster?

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.

How often does iCloud files sync?

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.

Why does my iPhone not sync with iCloud?

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.


1 Answers

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.

like image 94
RollRoll Avatar answered Sep 21 '22 07:09

RollRoll