【发布时间】:2014-08-18 12:41:51
【问题描述】:
我创建了一个从用户选择的文件夹加载 xml 文件的 mac 应用程序,在使用该应用程序后,用户保存了一个自定义文件 (.adgf) 当我尝试加载在一条记录中具有 xml 路径的 .adgf 文件(即 plist 文件)时,我调用 dictionaryWithContentsOfFile 但它给我一个“零”。我认为问题出在沙盒上(有时它有时会起作用)。字符串路径是正确的。 也许当用户加载 xml 文件时,我应该保存在特定应用程序“文档文件夹”中吗?
编辑: 我现在正在尝试 Bookmark Data 解决方案,并且我 retraive 一个 NSURL 但它不起作用。我使用的代码是这样的:
- (NSData *)bookmarkFromURL:(NSURL *)url {
NSError *error = nil;
NSData *bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys:NULL
relativeToURL:NULL
error:&error];
if (error) {
NSLog(@"Error creating bookmark for URL (%@): %@", url, error);
[NSApp presentError:error];
}
return bookmark;
}
- (NSURL *)urlFromBookmark:(NSData *)bookmark {
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark
options:NSURLBookmarkResolutionWithSecurityScope
relativeToURL:NULL
bookmarkDataIsStale:NO
error:NULL];
return url;
}
【问题讨论】: