码迷,mamicode.com
首页 > 移动开发 > 详细

iOS archiveRootObject 归档失败问题

时间:2015-12-03 13:23:52      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

归档失败问题出在路径上,NSHomeDirectory()

NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];

    stringPath = [stringPath stringByAppendingPathComponent:@"a.txt"];            // 成功

    NSLog(@"1111%@",stringPath);

    NSString * path2 = [NSHomeDirectory() stringByAppendingPathComponent:@"a.txt"];      // 失败,注意这里用的是NSHomeDirectory()

    NSLog(@"2222%@",path2);

    BOOL suc = [NSKeyedArchiver archiveRootObject:@"aaaa" toFile:path2];

    if (suc) {

        NSLog(@"user 归档成功!");

    }else{

        NSLog(@"user 归档失败!");

    }

 

1.NSHomeDirectory()  :  

/var/mobile/Containers/Data/Application/28C6BFE8-4E50-4DEB-9E55-18F0815CDBC5

2.[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0] :

/var/mobile/Containers/Data/Application/F7DC1040-57CB-4104-8AD6-55E9F287FC38/Documents/

看一下,

NSHomeDirectory() + /fileName   =  /var/mobile/Containers/Data/Application/28C6BFE8-4E50-4DEB-9E55-18F0815CDBC5/fileName  归档失败

[...NSDocumentDirectory...] +/fileName  = /var/mobile/Containers/Data/Application/F7DC1040-57CB-4104-8AD6-55E9F287FC38/Documents/fileName 成功 

红色区域是问题所在

iOS archiveRootObject 归档失败问题

标签:

原文地址:http://www.cnblogs.com/fengmin/p/5015688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!