如何在沙盒 Mac 应用程序中获取用户的下载文件夹,即 (~/Downloads)?
感谢帮助!
您可以为“下载”文件夹添加一项权利。
根据此 Apple 文档,您可以将“ com.apple.security.files.downloads.read-write
”添加到您的应用程序的权利文件中。
// 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;
}