【问题标题】:Storing UIManagedDocuments when uibiquity container (iCloud) is not available当 uibiquity 容器 (iCloud) 不可用时存储 UIManagedDocuments
【发布时间】:2013-04-27 18:13:24
【问题描述】:

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

所以当URLForUbiquityContainerIdentifier: 方法返回'nil'时,我使用建议的方法返回本地文档目录的URL

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

但是,当我尝试将 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);
                       }
                   }];
}

【问题讨论】:

    标签: uimanageddocument


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-02-07
      • 2014-12-27
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多