沙盒数据读取写入
NSString *doc=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString *path=[doc stringByAppendingPathComponent:@"account.archive”];
1.获取沙盒路径
2.如果是数组字典的话
[responseObject writeToFile:path atomically:YES];
NSDictionary *account=[NSDictionary dictionaryWithContentsOfFile:path];
3.如果是自定义Model的话
[NSKeyedArchiver archiveRootObject:account toFile:path];
AccountModel *account1=[NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSUserDefaults
NSString *key=@"CFBundleVersion";
写入:
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
// 这个不可省 立即执行
[[NSUserDefaults standardUserDefaults] synchronize];
读取:
NSString *lastVersion=[[NSUserDefaults standardUserDefaults] objectForKey:key];
// 从info.plist中获取版本号
NSString *currentVersion=[NSBundle mainBundle].infoDictionary[key];