2

我的应用程序有两种自定义文档类型。两者都在目标中声明,并导出它们的 UTI。两个 UTI 都符合 public.data 和 public.content;并且文档都使用 NSKeyedArchiver 来读写磁盘。

在 DocumentType1 的 NSDocument 子类中,在运行 NSOpenPanel 以找出要打开的 URL 后,我使用以下代码打开 DocumentType2 的文档:

self.docType2FileURL = [openPanel URLs][0];
NSLog(@"docType2FileURL: %@", self. docType2FileURL);
NSError *err = nil;
self.docType2FileSecurityScopedBookmark = [NSURL bookmarkDataWithContentsOfURL:self.docType2FileURL error:&err];
if (err != nil) {
    NSLog(@"bookmark error: %@", err);
}
NSLog(@"bookmark: %@", self.docType2FileSecurityScopedBookmark);
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:self.docType2FileURL display:NO completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    } else {
        NSLog(@"No error.");
    }
    self.docType2pointer = (DocumentType2 *)document;
}];

这是失败的,并导致以下日志语句:

2012-10-07 11:05:37.956 MyApp[64151:303] docType2FileURL: file://localhost/path/to/file2.docType2

2012-10-07 11:05:37.958 MyApp [64151:303] 书签错误:错误域 = NSCocoaErrorDomain 代码 = 256“无法打开文件。”

2012-10-07 11:05:37.959 MyApp [64151:303] 书签:(空)

2012-10-07 11:05:38.015 MyApp[64151:303] 错误:错误域 = NSCocoaErrorDomain 代码 = 256“无法打开文档“文件名 .docType2”。MyApp 无法打开此类型的文件。” UserInfo=0x1001b2c30 {NSLocalizedFailureReason=MyApp 无法打开此类型的文件。, NSLocalizedDescription=无法打开文档“name of file.docType2”。MyApp 无法打开此类型的文件。NSUnderlyingError=0x1005db460 ""name of file.docType2" 无法处理,因为 MyApp 无法打开此类型的文件。"}

无论出于何种原因,不仅文档无法打开,而且应用程序也无法为其创建书签。你对为什么会这样有任何想法吗?

提前致谢。

4

0 回答 0