沙盒數據讀取寫入
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];