沙盒數(shù)據(jù)讀取寫入
NSString *doc=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString *path=[doc stringByAppendingPathComponent:@"account.archive”];
1.獲取沙盒路徑
2.如果是數(shù)組字典的話
[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];
// 這個(gè)不可省 立即執(zhí)行
[[NSUserDefaults standardUserDefaults] synchronize];
讀?。?NSString *lastVersion=[[NSUserDefaults standardUserDefaults] objectForKey:key];
// 從info.plist中獲取版本號(hào)
NSString *currentVersion=[NSBundle mainBundle].infoDictionary[key];