IOS沙盒路径

来源:互联网 发布:app软件测试工程师 编辑:程序博客网 时间:2024/05/16 05:27

Xcode 7 的沙盒路径为:

模拟器沙盒路径:

/Users/a625/Library/Developer/CoreSimulator/Devices/2CFF7AE1-CDA8-444D-AAA6-2D51C6FF31EA/data/Containers/Data/Application/9DFC4962-0D8E-4ADE-9803-D0B707E6ACDC/Documents

1.获取沙盒路径的根路径:

//     获取沙盒的根路径    NSString *home = NSHomeDirectory();
2.拼接路径 :推荐第三种方式,呵呵

//     拼接Documents路径    1.NSString *docPath = [home stringByAppendingString:@"/Documents"];    2.NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];<pre name="code" class="objc">/**     *  NSDocumentDirectory : 查找Documents文件夹        NSUserDomainMask : 在用户的应用程序下查找     YES 把路径展开 NO 当前应用的根路径 == ~      NO  ~/Documents     */    3.NSString *docPath =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];    NSLog(@"%@",docPath);

3.拼接文件路径
// 拼接文件路径    NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"];
4.向该路径中存入数据就OK了

// 只有具备writeToFile:的对象才能使用plist存储,NSArray    NSArray *array = @[@1,@2,@"123"];        [array writeToFile:filePath atomically:YES];

这个时候就可以前往文章前面的那个文件夹下看到新建的plist文件了,并且可以打开看到里面的arry数组的数据了,over


0 0
原创粉丝点击