下面是获取沙盒文件路径的两种方法:
方法一:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imgPath = [documentsDirectory stringByAppendingPathComponent:@"loading.plist"];
方法二:
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/loading.plist"];
相对而言第二种方法比较简单 做了很久才理解这两种方法的区别
第一种方法可以直接获取到沙盒下Documents路径即AtIndex 0 取出的就是Documents的路径
第二种方法就是直接取出沙盒下的所有目录:Documents,temp,app,libiary
如果用第二种方法读取文件路径的时候,要把该文件对应的前一个目录写出来,想要写入到沙盒的时候也要加上前一个目录的路径,如果用第一种方法就可以不加前一个目录的路径