我如何获得“/library/containers”的路径/&quot目录
一个沙盒Macos应用程序可以轻松访问两个文件夹中的数据:
- 〜/library/containser/programName/
- 〜/library/group Containser/securityGroupname/
以下代码将为我提供“〜/library/group Container/”路径
let fileManager = FileManager.default
let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "myGroup")
print("path:",directory)
...将打印:
path:/users/myName/library/group Containers/myGroup
我想获得“〜/library/容器/”目录,而不是“〜/library/组集装箱” /“目录。
这必须很容易做到,因为它是一个通用目录。
有人知道如何使用Swift功能执行此操作吗?
我知道我可以用它来创建它:
var path: String = "/Users/etc/Containers/" + programName
A sandboxed macOS app can easily access data in two folders:
- ~/Library/Containers/ProgramName/
- ~/Library/Group Containers/SecurityGroupName/
The following code will give me the "~/Library/Group Container/" path ...
let fileManager = FileManager.default
let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "myGroup")
print("path:",directory)
This will print:
path: /Users/myName/Library/Group Containers/myGroup
I want to get the path of the "~/Library/Containers/" directory, not the "~/Library/Group Containers/" directory.
This must be easy to do, as it is a common directory.
Does anybody know how to do this using a Swift function?
I know I can just create it with:
var path: String = "/Users/etc/Containers/" + programName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在沙箱中,API
指向当前应用程序容器的用户库。
您无法访问更高级别的文件夹
〜/library/Containers
更新:
在iOS 16+中,Macos 13+有一个快捷方式,它将URL返回到
库
当前用户的文件夹。如果将应用程序打包给应用程序容器中的文件夹,则将URL点点为文件夹中的文件夹中的文件夹中的文件夹中的文件夹In the sandbox the API
points to the user library of the container of the current app.
You don't have access to the higher level folder
~/Library/Containers
Update:
In iOS 16+, macOS 13+ there is a shortcut, it returns the URL to the
Library
folder of the current user. If the app is sandboxed the URL points to folder in the application container otherwise to the folder in the home folder