0

我已经设法了解如何将 UIManagedDocument 合并到一个简单的测试应用程序中,并且它可以按预期工作!但是,现在我正在添加对这个基本应用程序的支持,因此如果用户不想使用 iCloud,它也可以工作。

因此,当该URLForUbiquityContainerIdentifier:方法返回“nil”时,我使用建议的方法返回本地文档目录的 URL

NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
return [NSURL fileURLWithPath:documentsDirectoryPath];

但是,当我尝试将 a 保存UIManagedDocument到本地 URL(例如:)时,file://localhost/var/mobile/Applications/some-long-identifier/Documents/d.dox我收到以下错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.'

使用此保存方法:

if (![[NSFileManager defaultManager] fileExistsAtPath:self.managedDocument.fileURL.path]) {
    [self.documentDatabase saveToURL:self.managedDocument.fileURL
                    forSaveOperation:UIDocumentSaveForCreating
                   completionHandler:^(BOOL success) {                           
                       if (success) {
                           //                               
                           //   Add default database stuff here.
                           //
                           dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                               [self.documentDatabase.managedObjectContext performBlock:^{
                                   [Note newNoteInContext:self.managedDocument.managedObjectContext];
                               }];
                           });
                       } else {
                           NSLog(@"Error saving %@", self.managedDocument.fileURL.lastPathComponent);
                       }
                   }];
}
4

1 回答 1

0

事实证明,我的持久存储选项包含用于无处不在的存储的密钥。这些不应该在文档持久存储选项中。

于 2013-04-27T20:04:51.340 回答