2

So I was migrating my Core Data to UIManagedDocument.

Calling openWithCompletionHandler on iPhone simulator works fine, but when I try to run my project on a real device it always returns NO. I override handleError and that's what I get:

    Error Domain=NSCocoaErrorDomain Code=260 
"The operation couldn’t be completed. (Cocoa error 260.)" 
UserInfo=0x1edafa90 {path=file://localhost/var/mobile/Applications/D57D7EAC-6E92-4CAD-97E7-179010CB6738/Project%20APP.app/DataModel.momd/StoreContent.nosync, NSUnderlyingError=0x1ed8e160 
"The operation couldn’t be completed. (Cocoa error 513.)", reason=Unable to restore path to store content}

And that's how I call it:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                          PrivateName, NSPersistentStoreUbiquitousContentNameKey,
                         //   cloudURL, NSPersistentStoreUbiquitousContentURLKey,
                         [NSNumber numberWithBool:YES],
                         NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES],
                         NSInferMappingModelAutomaticallyOption,
                         nil];
[self setPersistentStoreOptions:options];


[self openWithCompletionHandler:^(BOOL success) {
    if (success)
    NSLog(@"opened");
    else {
        NSLog(@"Not opened");
    }
}];
Alex Fi
  • 45
  • 2
  • 6

1 Answers1

0

If you're trying to open a document in iCloud, you need BOTH NSPersistentStoreUbiquitousContentNameKey and NSPersistentStoreUbiquitousContentURLKey to be set in the persistentStoreOptions - you currently have commented out NSPersistentStoreUbiquitousContentURLKey.

If you're trying to open a document local to the device, then you want neither of these keys set in the options.

I'm guessing in your case that this works on the simulator, but not the device, because the simulator is not currently capable of opening documents in iCloud. On the other hand, devices are capable of opening documents in iCloud, and you're not giving it enough information to do that properly, so its borking.

Rob Glassey
  • 2,237
  • 20
  • 21