-Documents
-Library
-Caches
-References
-tmp
获取根目录
真机和模拟器路径可能不同,待验证
NSString *sandBoxRootDir = NSHomeDirectory();
获取Documents路径
// NSSearchPathForDirectoriesInDomains返回的是一个数组,但这里第一个参数是NSDocumentDirectory,返回数组里只有一个,所以用了lastObject, 也可以用[paths objectAtIndex:0]
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths lastObject];
获取Library路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths lastObject];
获取Caches路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDirectory = [paths lastObject];
Preferences路径
通过NSUserDefaults存取数据
获取tmp路径
NSString *tmpDirectory = NSTemporaryDirectory();
网友评论