【发布时间】:2012-01-10 21:45:32
【问题描述】:
我在 iOS 5.0 中使用 UIManagedDocument,在模拟器上运行应用程序,在 OSX 10.6 下使用 XCode 4.2。有问题的代码如下所示:
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.photoDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.photoDatabase saveToURL:self.photoDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
[self setupFetchedResultsController];
[self fetchFlickrDataIntoDocument:self.photoDatabase];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateClosed) {
// exists on disk, but we need to open it
// *** the following line generates the message ***
[self.photoDatabase openWithCompletionHandler:^(BOOL success) {
//[self setupFetchedResultsController];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateNormal) {
// already open and ready to use
[self setupFetchedResultsController];
}
运行标记的行会在日志中创建以下消息:
2012-01-10 22:33:17.109 Photomania[5149:4803] NSFileCoordinator: A surprising server error was signaled. Details: Connection invalid
消息发送后,UIManagedDocument 可能工作也可能不工作——我还没有找到决定这一点的情况。
我很确定代码是正确的,因为它实际上是斯坦福 CS193p 课程中的代码示例之一。整个示例可以在他们的网站上下载 http://www.stanford.edu/class/cs193p/cgi-bin/drupal/ 直接链接到代码: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/Photomania_0.zip
此外,代码在设备本身上运行良好,不会产生“令人惊讶”的消息,并且运行之后的所有代码都很好。
我没有在 Google 上找到任何东西,在 Apple 开发者页面上也没有。重新启动模拟器或 XCode,或重新安装它们都不会改变行为。
有什么想法吗?
【问题讨论】:
-
你有什么办法吗? cs193p 项目仅适用于 iPhone。你的是通用的吗?你认为这重要吗?
-
我没有,而且它现在大部分时间都在工作,所以目前它不是高优先级。我自己的项目是通用的,但是,我在 cs193p 项目上看到了与从他们的网页下载的相同的项目。
-
请注意,由于我已将所有项目升级到 iOS 5.0,因此我无法再对此进行测试,并且该错误不再发生。
标签: ios core-data ios-simulator uimanageddocument nsfilecoordinator