如何在沙盒应用程序中获取/Users/username/Downloads路径? [英] how to get /Users/username/Downloads path in a sandboxed app?

查看:74
本文介绍了如何在沙盒应用程序中获取/Users/username/Downloads路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的是将 com.apple.security.files.downloads.read-write 设置为 true ,并查看了与Apple Sandbox相关的文档,但我不知道如何获取下载文件夹路径,我仍然得到的是这样的容器路径:/Users/username/Library/Containers/com.errpro.Snell/Data/Downloads ,我使用的方法是 NSSearchPathForDirectoriesInDomains .我见过有人使用 getpwent 来获取路径,但似乎不合适.任何帮助将不胜感激.

what I've done is setup the com.apple.security.files.downloads.read-write to true, and have looked up the Apple Sandbox related docs, but I can't figure out how to get the downloads folder path, what I get is still container path like this: /Users/username/Library/Containers/com.errpro.Snell/Data/Downloads , the method I use is NSSearchPathForDirectoriesInDomains. I've seen someone use getpwent to get the path, but seems not appropriate. Any help would be appreciated.

推荐答案

您应使用URLForDirectory方法.此方法找到当前用户的名称并将其插入URL路径.

You should use the method URLForDirectory. This method find the name of the current user and insert it in the URL path.

NSFileManager       *fm = [NSFileManager defaultManager];
NSURL               *downloadsURL;  

downloadsURL = [fm URLForDirectory:NSDownloadsDirectory
                   inDomain:NSUserDomainMask appropriateForURL:nil
                   create:YES error:nil];

这篇关于如何在沙盒应用程序中获取/Users/username/Downloads路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆