关闭

沙盒目录结构

127人阅读 评论(0) 收藏 举报
分类:

沙盒的目录结构:

默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp。因为应用的沙盒机制,应用只能在几个目录下读写文件
Documents:苹果建议将程序中建立的或在程序中浏览到的文件数据保存在该目录下,iTunes备份和恢复的时候会包括此目录

Library下有两个文件夹,Caches存储应用程序再次启动所需的信息,Preferences包含应用程序偏好设置文件

Library/Caches:存放缓存文件,iTunes不会备份此目录,此目录下文件不会在应用退出删除

tmp:提供一个即时创建临时文件的地方。


1、获取程序的Home目录

NSString *homeDirectory = NSHomeDirectory();  

打印结果:

NSHomeDirectory = /Users/xxx/Library/Developer/CoreSimulator/Devices/D0A73DBD-2084-41F6-A696-0BABA0438077/data/Containers/Data/Application/61C513B4-FB4B-4669-A523-5BA9B9CBD73D 

2、获取document目录

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectoryNSUserDomainMaskYES);

NSLog(@"paths = %@", [paths lastObject]);

打印结果:

paths = /Users/xxx/Library/Developer/CoreSimulator/Devices/D0A73DBD-2084-41F6-A696-0BABA0438077/data/Containers/Data/Application/DACE2E71-3C2F-4060-BE6C-942DC8920C0B/Library/Documentation

3、获取Cache目录

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectoryNSUserDomainMaskYES);

NSLog(@"paths = %@", [paths lastObject]);

打印结果:

paths = /Users/xxx/Library/Developer/CoreSimulator/Devices/D0A73DBD-2084-41F6-A696-0BABA0438077/data/Containers/Data/Application/8CB9F194-B7F7-49B9-AD30-0C2F30DD7AE9/Library/Caches

4、获取Library目录

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectoryNSUserDomainMaskYES);

NSLog(@"paths = %@", [paths lastObject]);

打印结果:

paths = /Users/xxx/Library/Developer/CoreSimulator/Devices/D0A73DBD-2084-41F6-A696-0BABA0438077/data/Containers/Data/Application/B89DC285-5DE4-4454-A0A3-CD695F2F6775/Library

5. 获取Tmp目录

NSString *paths = NSTemporaryDirectory();

 NSLog(@"NSTemporaryDirectory = %@",paths);

NSTemporaryDirectory = /Users/xxx/Library/Developer/CoreSimulator/Devices/D0A73DBD-2084-41F6-A696-0BABA0438077/data/Containers/Data/Application/79B07095-F13B-4058-81D7-BBCE555A3B75/tmp/

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36420次
    • 积分:621
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:152篇
    • 译文:0篇
    • 评论:0条
    文章分类