iOS 本地缓存 归档数据模型化
来源:互联网 发布:php apache forbidden 编辑:程序博客网 时间:2024/06/06 02:59
-(void)getHomeurl:(NSString *)url
{
NSMutableDictionary *param = [NSMutableDictionarydictionary];
if ([urlisEqualToString:KgetHomePageV20]){
[param setValue:KmemberIdforKey:@"memberId"];
// [param setValue:@"4" forKey:@"advertisementSize"];
// [param setValue:@"3" forKey:@"recommendationSize"];
[param setValue:@"9"forKey:@"shotSize"];
[param setValue:KAPPIDforKey:@"appId"];
[param setValue:KappSecretforKey:@"appSecret"];
[param setValue:[CommonToolsgetTimeScamp] forKey:@"timestamp"];
//加密规则:sign=md5(app_id + lon+lat + time + key)
[param setValue:[CommonToolstokenmd5StringFromArray:@[[NSStringstringWithFormat:@"memberId%@",param[@"memberId"]],[NSStringstringWithFormat:@"shotSize%@",param[@"shotSize"]],[NSStringstringWithFormat:@"appId%@",param[@"appId"]],[NSStringstringWithFormat:@"appSecret%@",param[@"appSecret"]],[NSStringstringWithFormat:@"timestamp%@",param[@"timestamp"]]]]forKey:@"digest"];
}elseif ([url isEqualToString:KISUntreatedInfoV17]){
NSString *requestTime;
if ([[UserModelsharedInstance].oldDatelength] > 0 ) {
requestTime = [UserModelsharedInstance].oldDate;
}else{
requestTime = @"0";
}
[param removeAllObjects];
[param setValue:KmemberIdforKey:@"memberId"];
[param setValue:requestTimeforKey:@"lastDynamicId"];
[param setValue:KAPPIDforKey:@"appId"];
[param setValue:KappSecretforKey:@"appSecret"];
[param setValue:[CommonToolsgetTimeScamp] forKey:@"timestamp"];
[param setValue:[CommonToolstokenmd5StringFromArray:@[[NSStringstringWithFormat:@"memberId%@",param[@"memberId"]],[NSStringstringWithFormat:@"lastDynamicId%@",param[@"lastDynamicId"]],[NSStringstringWithFormat:@"appId%@",param[@"appId"]],[NSStringstringWithFormat:@"appSecret%@",param[@"appSecret"]],[NSStringstringWithFormat:@"timestamp%@",param[@"timestamp"]]]]forKey:@"digest"];
}
else{
param = nil;
}
[HTTPRequestToolsendGetAFRequest:url withParameters:param withSuccess:^(id message) {
NSDictionary *tempArr = [NSJSONSerializationJSONObjectWithData:messageoptions:NSJSONReadingMutableContainerserror:nil];
DSLog(@"我的首页数据tempArr = %@",tempArr);
// /**
if ([urlisEqualToString:KgetHomePageV20]){
[_homeVideoArrremoveAllObjects];
[_homeDyArrremoveAllObjects];
[_homeAdArrremoveAllObjects];
for (NSDictionary * tempDicin tempArr[@"myShots"] ) {
MorevideoNewModel *moreVDModel = [[MorevideoNewModelalloc]init];
[moreVDModel setValuesForKeysWithDictionary:tempDic];
[_homeVideoArraddObject:moreVDModel];
}
for (NSDictionary *temDicin tempArr[@"golfDynamics"]) {
golfDynamicsModel *golfModel = [[golfDynamicsModelalloc]init];
[golfModel setValuesForKeysWithDictionary:temDic];
[_homeDyArraddObject:golfModel];
}
for (NSDictionary *temDicin tempArr[@"advertisements"]) {
advertisementsModel * adModel = [[advertisementsModelalloc]init];
[adModel setValuesForKeysWithDictionary:temDic];
[_homeAdArraddObject:adModel];
}
NSLog(@"从网络中获取数据 --- 缓存到本地");
[[JXTCachercacher] setObject:_homeVideoArr// save data to local disk and cache
forKey:@"myShots"
userId:@"myShots01"
useArchive:YES
setted:^(JXTCacher *cacher,CacheError error) {
}];
[[JXTCachercacher] setObject:_homeDyArr// save data to local disk and cache
forKey:@"golfDynamics"
userId:@"golfDynamics01"
useArchive:YES
setted:^(JXTCacher *cacher,CacheError error) {
}];
[[JXTCachercacher] setObject:_homeAdArr// save data to local disk and cache
forKey:@"advertisements"
userId:@"advertisements01"
useArchive:YES
setted:^(JXTCacher *cacher,CacheError error) {
}];
[self.homeCollectionViewreloadData];
}elseif ([url isEqualToString:KISUntreatedInfoV17]){
DSLog(@"----------returnCode--------%@",tempArr[@"returnCode"]);
if ([tempArr[@"returnCode"]isEqualToString:@"29"] || [tempArr[@"returnCode"]isEqualToString:@"31"]) {
[[NSNotificationCenterdefaultCenter]postNotificationName:@"TokenFail"object:nil];
}
// NSString *oldDateStr = [messageBody.regDate stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
// [UserModel sharedInstance].oldDate = oldDateStr;
ISUntreatedInfoModel *isModel = [[ISUntreatedInfoModelalloc]init];
[isModel setValuesForKeysWithDictionary:tempArr];
//通讯录
if (isModel.ISUntreatedFriendInfo >0) {
[UserModelsharedInstance].ISUntreatedFriendInfo = [NSStringstringWithFormat:@"%d",isModel.ISUntreatedFriendInfo];
UIViewController *cvc = [[UIViewControlleralloc]init];
cvc.view.tag =4;
NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:cvc,@"RedDot",nil];
NSNotification *notification = [NSNotificationnotificationWithName:@"RedDot"object:niluserInfo:dict];
[[NSNotificationCenterdefaultCenter]postNotification:notification];
}else{
UIViewController *cvc = [[UIViewControlleralloc]init];
cvc.view.tag =3;
NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:cvc,@"RedDot",nil];
NSNotification *notification = [NSNotificationnotificationWithName:@"RedDot"object:niluserInfo:dict];
[[NSNotificationCenterdefaultCenter]postNotification:notification];
}
//动态
if (isModel.ISNewDynamic >0) {
UIViewController *cvc = [[UIViewControlleralloc]init];
cvc.view.tag =1;
NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:cvc,@"RedDot",nil];
NSNotification *notification = [NSNotificationnotificationWithName:@"RedDot"object:niluserInfo:dict];
[[NSNotificationCenterdefaultCenter]postNotification:notification];
}else{
UIViewController *cvc = [[UIViewControlleralloc]init];
cvc.view.tag =0;
NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:cvc,@"RedDot",nil];
NSNotification *notification = [NSNotificationnotificationWithName:@"RedDot"object:niluserInfo:dict];
[[NSNotificationCenterdefaultCenter]postNotification:notification];
}
}
} andWithFail:^(id message) {
NSLog(@"error = %@",message);
}];
}
-(void)loadData
{
[[JXTCachercacher] objectForKey:@"myShots"userId:@"myShots01"achive:^(JXTCacher *cacher,id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error ==0) { //local or cache have data
_homeVideoArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionViewreloadData];
}
else {// local and cache have no data
[selfgetHomeurl:KGetHomePage];
NSLog(@"从网络中获取数据");
}
});
}];
[[JXTCachercacher] objectForKey:@"golfDynamics"userId:@"golfDynamics01"achive:^(JXTCacher *cacher,id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error ==0) { //local or cache have data
_homeDyArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionViewreloadData];
}
});
}];
[[JXTCachercacher] objectForKey:@"advertisements"userId:@"advertisements01"achive:^(JXTCacher *cacher,id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error ==0) { //local or cache have data
_homeAdArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionViewreloadData];
}
});
}];
}
- iOS 本地缓存 归档数据模型化
- iOS 本地缓存 归档数据模型化 .m
- iOS 本地持久化 "归档"
- iOS开发缓存:本地缓存
- ios 本地缓存
- IOS 本地缓存
- iOS开发本地缓存
- iOS 本地缓存实现
- <iOS>本地缓存
- IOS图片缓存本地
- ios本地缓存机制
- iOS 清理本地缓存
- iOS 数据的本地存储-对象归档
- iOS 归档 保存对象到本地
- iOS本地存储1--NSkeyedArchiever归档
- iOS本地存储0--plist归档
- iOS开发------本地存储-NSKeyedArchiver & NSKeyedUnarchiver(归档)
- iOS本地存储 plist文件和归档
- 【ibatis】ibatis 中 $与#的区别
- (五)判断两个词是否为变位词的算法
- Spring框架自动装配 Bean(三)
- js控制一个按钮是否可点击(可使用)disabled
- iOS 定位
- iOS 本地缓存 归档数据模型化
- iOS-获取的NSDate date时间与实际相差8个小时解决方案
- HDU1754 线段树 单点修改 最大值(基础题)
- eclipse打包maven工程文件提示找不到tools.jar的解决办法
- ZK安装及kafka基本运行小结
- improving sql server performance
- java Iterable and for each
- iOS-字符串转化成NSDate类型 计算与当前时间的相差 月数 天数
- java中的多线程包--- Executor详细介绍 打造基于Executor的Web服务器