2013-01-15 57 views
2

所以我正在将我的Core Data迁移到UIManagedDocument。UIManagedDocument openWithCompletionHandler返回NO

在iPhone模拟器上调用openWithCompletionHandler可以正常工作,但是当我尝试在真实设备上运行我的项目时,它始终返回NO。我重写的HandleError,这就是我得到:

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} 

这就是我怎么称呼它:

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"); 
    } 
}]; 

回答

0

如果你试图打开iCloud中的文档,你既需要NSPersistentStoreUbiquitousContentNameKeyNSPersistentStoreUbiquitousContentURLKey在persistentStoreOptions中设置 - 您当前已注释掉NSPersistentStoreUbiquitousContentURLKey。

如果您尝试打开设备本地的文档,那么您不需要在选项中设置这些键。

我猜你的情况下,这可以在模拟器上,但不是设备,因为模拟器目前无法在iCloud中打开文档。另一方面,设备能够在iCloud中打开文档,而且您没有提供足够的信息来做到这一点,所以它的博客。

相关问题