一、开启iTunes访问沙盒文件夹权限
在 Info.plist 文件中添加UIFileSharingEnabled
这个Key, 并设置该值为 YES
即可
在填写完 UIFileSharingEnabled
并回车后, 发现会自动更正为Application supports iTunes file sharing
, 将值设置为YES
即可
二、
// 打开沙盒下Documents文件夹下的hahaha.txt文件
+(NSString*)readFileInDocuments{
// 获取沙盒主文件夹路径
// NSString *homeDir = NSHomeDirectory();
// 获取Documents文件夹路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
// 获取Caches文件夹路径
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
// NSString *cachesDir = [paths objectAtIndex:0];
// 获取tmp文件夹路径
// NSString *tmpDir = NSTemporaryDirectory();
NSString *urlPath = [NSString stringWithFormat:@"%@/hahaha.txt",docDir];
NSString *myContents = [NSString stringWithContentsOfFile:urlPath encoding:NSUTF8StringEncoding error:nil];
return myContents;
}