获取 iOS 应用程序的“~/Library”可靠的路径

发布于 2024-09-24 05:08:45 字数 302 浏览 1 评论 0原文

此 Apple 技术说明:

http://developer.apple.com/library /ios/#qa/qa2010/qa1699.html

建议将“内部”用户文档存储在 ~/Library 的子目录中。但我找不到可以帮我找到这个的预先创建的搜索域之一。构建这条路径的最佳/最正确/最不可能破坏的方式是什么?

谢谢。

This Apple tech note:

http://developer.apple.com/library/ios/#qa/qa2010/qa1699.html

suggests storing "internal" user documents in a subdirectory off of ~/Library. But I can't find one of the pre-created search domains that would get me this. What's the best/most correct/least likely to ever break way of constructing this path?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星光不落少年眉 2024-10-01 05:08:45

正确的方法是

NSString* path;
path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];

但是,[@"~/Library" stringByExpandingTildeInPath]也有效。


斯威夫特3:

let path = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]

The correct way is

NSString* path;
path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];

However, [@"~/Library" stringByExpandingTildeInPath] also works.


Swift 3:

let path = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
泪是无色的血 2024-10-01 05:08:45

你也可以尝试这个:

[NSHomeDirectory() stringByAppendingString:@"/Library"]

You can also try this:

[NSHomeDirectory() stringByAppendingString:@"/Library"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文