获取iOS应用程序的“〜/ Library”可靠的路径 [英] Getting an iOS application's "~/Library" path reliably

查看:199
本文介绍了获取iOS应用程序的“〜/ Library”可靠的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

苹果技术说明:

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



建议储存位于〜/ Library 之外的子目录中的internal用户文档。但我无法找到一个预先创建的搜索域,这将使我这个。什么是最好的/最正确的/最不可能打破这种路径的方式?

谢谢。

解决方案

正确的方法是

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

然而, [@〜/ LibrarystringByExpandingTildeInPath]


Swift 3:

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


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.

解决方案

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]

这篇关于获取iOS应用程序的“〜/ Library”可靠的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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