沙盒路径
NSHomeDirectory()
/var/mobile/Containers/Data/Application/213DA05A-7967-49A5-83C0-B34C0C626C56
关于/var文件夹的解释是 "/var" is usually used for log files, 'temporary' files (like mail spool, printer spool, etc), databases, and all other data not tied to a specific user. Logs are usually in "/var/log", databases in "/var/lib" (mysql - "/var/lib/mysql"), etc.
/var 通常用来存储系统运行时日志文件,临时文件和公用数据,从沙盒的路径来看,var文件夹存储了iOS系统中所有app运行后产生的数据,沙盒是一个以唯一字符串命名的文件夹。
临时文件路径
在沙盒下的tmp文件夹中
NSTemporaryDirectory()
/var/mobile/Containers/Data/Application/213DA05A-7967-49A5-83C0-B34C0C626C56/tmp/
app用户的文件夹路径 Documents
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) firstObject]
/var/mobile/Containers/Data/Application/213DA05A-7967-49A5-83C0-B34C0C626C56/Documents
临时库文件夹 Library
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES) firstObject]
/var/mobile/Containers/Data/Application/213DA05A-7967-49A5-83C0-B34C0C626C56/Library
缓存文件夹在库文件夹的下一级
[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) firstObject]
/var/mobile/Containers/Data/Application/213DA05A-7967-49A5-83C0-B34C0C626C56/Library/Caches
==============分割线=================
应用的bundle路径 同样也在var文件夹下,按理说应该在usr里的
[[NSBundle mainBundle] bundlePath]
/var/containers/Bundle/Application/37770E10-9334-46D2-AE64-24D0D0D45616/name.app/
总结:
- 沙盒文件夹存储在 unix-like 系统的 /var/mobile/Containers/Data/Application/ 文件夹下 (移动-容器-数据-应用)
- NSBundle mainBundle 的路径是
/var/containers/Bundle/Application/ 文件夹下(容器-包-应用)- NSData writetToFile 方法无法在bundle文件夹中进行写入操作,文件夹为只读属性。
补充
info.plist在mainBundle里,所以获取info.plist的方法是
[[NSBundle mainBundle] infoDictionary];
参考链接:1. https://serverfault.com/questions/384342/what-are-the-best-practices-of-the-usr-var-and-etc-folders
2.https://blog.csdn.net/liudukun/article/details/23994039
网友评论