用于在沙盒应用中在Mac上获取用户下载文件夹的API

时间:2012-11-02 04:57:30

标签: objective-c macos

如何在沙盒mac app中获取用户的下载文件夹,即(〜/ Downloads)?

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

您可以为“下载”文件夹添加权利。

According to this Apple document,您可以在应用的权利文件中添加“com.apple.security.files.downloads.read-write”。

答案 1 :(得分:0)

// App Sandbox:
// Project / Target / Signing & Capabilities / App Sandbox / File Access / Downloads Folder:
// "com.apple.security.files.downloads.read-write" OR "*.read-only"
- (NSURL*)downloadsURL:(NSError**)error{
    NSFileManager *fm = [NSFileManager defaultManager];
    NSURL *sandboxDownloadsURL = [fm URLForDirectory:NSDownloadsDirectory
                                            inDomain:NSUserDomainMask
                                   appropriateForURL:nil
                                              create:YES
                                               error:error];
    NSURL *resolvedURL = sandboxDownloadsURL.URLByResolvingSymlinksInPath;
    return resolvedURL;
}