NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:firstDownLoad forKey:@"firstDownLoad_2.0_1”];
//NSUserDefaults用户本地 给firstDownLoad设置一个值
//第一次下载 2.0版本的时候 注册此通知
if ([[NSUserDefaults standardUserDefaults]objectForKey:@"firstDownLoad"] == nil || [[NSUserDefaults standardUserDefaults]objectForKey:@"firstDownLoad_2.0_1"] == nil){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_creatZhiNanImgView) name:@"creatZhiNanImgView" object:nil]; }
2.运用plist文件
(1)//写入plist的代码:
//文件管理器
NSFileManager *fileManager = [NSFileManager defaultManager];
//1.获取文件的存取路径
NSString *createPath = [self dataFilepath];
// 判断文件夹是否存在,如果不存在,则创建
if (createPath == nil) {
//如果没有就创建这个 想创建的文件夹
NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
//2.获取得到的元素的字符串,并创建一个名为Column.plist的.plist文件用于保存数据
NSString *defaulPath = [pathDocuments stringByAppendingPathComponent:@"Column.plist"];
NSError *errer;
BOOL succes = [fileManager copyItemAtPath:defaulPath toPath:createPath error:&errer];
if(!succes){
NSLog(@"复制 失败");
}else{
[array writeToFile:createPath atomically:YES];
}
}else{
[array writeToFile:createPath atomically:YES];
}
#pragma mark --获取文件路径
-(NSString *)dataFilepath{
//1.获取文件路径数组
NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
//2.获取得到的元素的字符串,并创建一个名为Column.plist的.plist文件用于保存数据
NSString *defaulPath = [pathDocuments stringByAppendingPathComponent:@"Column.plist"];
return defaulPath;
}
(2)//从plist文件中取出数据:
//从文件 取数据
NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString *createPath=[pathDocuments stringByAppendingPathComponent:@"Column.plist"];
NSMutableArray * historylanmuArr = [[NSMutableArray alloc] initWithContentsOfFile:createPath];