-
App内目录结构:
-
读写权限与功能:
iOS开发是在沙盒中,对于开发者有读写权限的目录,如下:
Documents:需要始终被保存的数据存储到这里,iTunes在备份和恢复时包含此目录。
Library/Caches:缓存一般性的文件,iTunes不会备和恢复份此目录,该目录不会在应用退出是被清空。
tmp:存放临时文件,iTunes不会备份和恢复此目录,该目录下文件可能会在应用退出后删除。
-
获取方式:
Home:
NSLog(@"NSHomeDirectory = %@",NSHomeDirectory());
输出:
/var/mobile/Containers/Data/Application/8E016CC3-4574-40BB-80AB-8714FBF3C069
Documents:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory
, NSUserDomainMask
, YES);
NSLog(@"path = %@",documentPaths.firstObject);
输出:
/var/mobile/Containers/Data/Application/8E016CC3-4574-40BB-80AB-8714FBF3C069/Documents
*注:NSDocumentDirectory 是指程序中对应的Documents路径,而NSDocumentionDirectory对应于程序中的Library/Documentation路径,这个路径是没有读写权限的,所以看不到文件生成。
Library/Caches:
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory
, NSUserDomainMask
, YES);
NSLog(@"cachePath = %@",cachePaths.firstObject);
输出:
/var/mobile/Containers/Data/Application/8E016CC3-4574-40BB-80AB-8714FBF3C069/Library/Caches
tmp:
NSTemporaryDirectory()
NSLog(@"NSHomeDirectory = %@",NSTemporaryDirectory());
输出:
/private/var/mobile/Containers/Data/Application/8E016CC3-4574-40BB-80AB-8714FBF3C069/tmp/