Take the 2-minute tour ×

This is the code i used in the init for storage class and it worked fine until recently.. when i tried testing it, it crashes (marked below) at addPersistentStoreWithType ... i noticed this after switching to the iPhone 5 and was trying to run the app... but if i turn off icloud on my phone or test it on the simulator there are no problems...

    self = [super init];
        NSLog(@"%s", __FUNCTION__);
        favColors = [[NSMutableArray alloc] init];
        model = [NSManagedObjectModel mergedModelFromBundles:nil];
        NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
        NSString *path = [self itemArchivePath];
        NSURL *storeURL = [NSURL fileURLWithPath:path];
        NSError *error = nil;
        NSMutableDictionary *options = [NSMutableDictionary dictionary];

        NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
        if (ubiq) {
            NSLog(@"iCloud access at %@", ubiq);
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(contentChange:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:nil];
            NSFileManager *fm = [NSFileManager defaultManager];
            NSURL *ubcontainer = [fm URLForUbiquityContainerIdentifier:nil];
            [options setObject:@"color" forKey:NSPersistentStoreUbiquitousContentNameKey];
            [options setObject:ubcontainer forKey:NSPersistentStoreUbiquitousContentURLKey];

        } else {
            NSLog(@"No iCloud access");
   // ************ Crash here **************
        if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:(ubiq?options:nil) error:&error]) {
            [NSException raise:@"Open failed" format:@"Reason: %@", [error localizedDescription]];
        context = [[NSManagedObjectContext alloc] init];
        [context setPersistentStoreCoordinator:psc];
        [context setUndoManager:nil];

        [self loadAllItems];
    return self;

- (NSString *)itemArchivePath
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectories objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"store.data"];

Also if i run the app once and turn off icloud after the crash and run the app again.. the data is retrieved from icloud... and shows on app.

The out put log shows this.

iCloud access at file://localhost/private/var/mobile/Library/Mobile%20Documents/xxx -PFUbiquitySetupAssistant performPreStoreSetupWithError:: CoreData: Ubiquity: The baseline file exists, but could not be read

share|improve this question
Also after i went into iCloud>Storage and Backup>Manage Storage and deleted the data for the app it works fine... and the previous data is back... :/ –  Amorn Narula Mar 10 '13 at 5:54
add comment

1 Answer

That's an internal iCloud error. It's not your fault, and there's nothing you can do in code that would fix or prevent it. It will happen randomly, with no predictable pattern for when or why. Deleting data for the app is, unfortunately, the only real solution. Doing that only deletes iCloud's copy of the data, not data stored in your app's Documents directory or other non-iCloud locations, so it's not surprising that the old data would still be present.

share|improve this answer
so should i put this down in the app description for people who experience this problem ?.. i don't even know if they have this problem or not.. i did and i tried it on my friend's phone, it occurred as well. –  Amorn Narula Mar 12 '13 at 4:19
Oh, it's out in the field already? That's unfortunate. Your users will probably have problems at some point, but maybe not immediately. You probably hit it first because, since you're developing the app, you use it more. You could put it in the app description, or on your web site, but you should try to jell the, out somehow. –  Tom Harrington Mar 12 '13 at 4:28
Cool, thnx.. was really hoping there was a fix for it.. din wanna put it in the description. –  Amorn Narula Mar 14 '13 at 10:30
lol just got my first review for this problem... black screen and crash... –  Amorn Narula Mar 14 '13 at 10:35
Isn't there something like a try catch I can put that in to counter the error ? –  Amorn Narula Mar 19 '13 at 13:51
show 3 more comments

Your Answer


