IOS常用获取沙盒路径,URL方法


存储到沙盒Documents文件夹下:(Documents文件夹因为可以同iCloud同步备份的关系,不可以存放大量临时数据,否则应用无法通过审核)
1.
NSString *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
2.
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/text.txt”]; (其他"Documents"路径也可以像这样手动填写)


获得沙盒Documents文件夹URL
   NSFileManager *manager = [NSFileManager defaultManager];
    NSURL *url = [[manager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
    NSURL *path = [url URLByAppendingPathComponent:@"MyDocument"];


存储的沙盒Temp文件夹下:
NSString *temp = NSTemporaryDirectory();

存储的沙盒Cache文件夹下:
    NSString *cache = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];


存储的沙盒根目录下:
1.
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"text.txt"];
2.
NSString *userName = NSUserName();
    NSString *userPath = NSHomeDirectoryForUser(userName);

你可能感兴趣的:(IOS开发)