热更新demo

TPUserDefault.m 42KB

    // // TPUserDefault.m // ThePaperDemo // // Created by Scar on 14-9-10. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "TPUserDefault.h" #import <AdSupport/AdSupport.h> #import "AppDelegate.h" //#import "YRSideViewController.h" #import "SDImageCache.h" #import "TPMainPageViewController.h" #import "searchStrDB.h" static TPUserDefault *userDefaultsInstance = nil; @interface TPUserDefault()<RemoteDelegate> @property(nonatomic, strong)NSUserDefaults *defaults; @end @implementation TPUserDefault @synthesize defaults; @synthesize currentPageIndex; @synthesize channldataList = _channldataList; @synthesize isUseSystemFont = _isUseSystemFont; @synthesize isNightMode = _isNightMode; @synthesize userBO = _userBO; @synthesize visitTime = _visitTime; @synthesize lastContentID,lastContentOffset; @synthesize uuid = _uuid; @synthesize offlineList = _offlineList; @synthesize offlineStatusList = _offlineStatusList; @synthesize isOffline; @synthesize umengToken; @synthesize pushBO = _pushBO; @synthesize isEnterFromBackground; @synthesize imageQueue,globalQueue; @synthesize isFirstIntoApp = _isFirstIntoApp; @synthesize contFontSize = _contFontSize; @synthesize hotAskColorList; @synthesize registerBO; @synthesize fogetPwdInfoBO; @synthesize msgMark = _msgMark; @synthesize updateInfo; @synthesize ignoreVersion = _ignoreVersion; @synthesize isOpenPush = _isOpenPush; @synthesize appVersion = _appVersion; @synthesize orderEventTempList; @synthesize isIphone4; @synthesize offlineController; @synthesize offlinePath; @synthesize pauseDataDic = _pauseDataDic; @synthesize readModeStr = _readModeStr; @synthesize noMoreReadModeAlert = _noMoreReadModeAlert; @synthesize helpArray = _helpArray; @synthesize searchHistoryArray = _searchHistoryArray; @synthesize localCollectArray = _localCollectArray; @synthesize memoryPointArray = _memoryPointArray; @synthesize videoDefinition = _videoDefinition; @synthesize isAttention = _isAttention; @synthesize isRegistedPush = _isRegistedPush; + (TPUserDefault *)instance { @synchronized(self) { if (userDefaultsInstance == nil) { userDefaultsInstance = [[self alloc] init]; NSDictionary *dic = @{@"type":@"1"}; [Remote doJsonActionWithBlock:1 requestUrl:allNodeListURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (responseData && responseData[@"nodeList"]) { NSMutableArray *channalList = [TPUserDefault instance].channldataList; if (channalList.count == 0) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSString *nodeID = obj[@"nodeId"]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:obj]; [dic setValue:[[TPUserDefault instance] getContollerNameWithNodeId:nodeID] forKey:@"controller"]; NSString *color = dic[@"color"]; color = [color substringWithRange:NSMakeRange(1, 6)]; color = [NSString stringWithFormat:@"0x%@",color]; [dic setValue:color forKey:@"color"]; [tempArray addObject:dic]; }]; if (tempArray.count == 7) { [TPUserDefault instance].channldataList = tempArray; } }else { NSMutableArray *tempArray = [NSMutableArray array]; [channalList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:obj]; NSString *nodeID = obj[@"nodeId"]; NSArray *nodeArray = responseData[@"nodeList"]; __block NSMutableDictionary *oriDic = dic; [nodeArray enumerateObjectsUsingBlock:^(id item, NSUInteger index, BOOL *stop1) { if ([nodeID intValue] == [item[@"nodeId"] intValue]) { oriDic = [NSMutableDictionary dictionaryWithDictionary:item]; [oriDic setValue:[[TPUserDefault instance] getContollerNameWithNodeId:nodeID] forKey:@"controller"]; NSString *color = oriDic[@"color"]; color = [color substringWithRange:NSMakeRange(1, 6)]; color = [NSString stringWithFormat:@"0x%@",color]; [oriDic setValue:color forKey:@"color"]; *stop1 = YES; } }]; [tempArray addObject:oriDic]; }]; if (tempArray.count == 7) { [TPUserDefault instance].channldataList = tempArray; } } } }]; dic = @{@"type":@"4"}; [Remote doJsonActionWithBlock:2 requestUrl:allNodeListURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (responseData && responseData[@"nodeList"]) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeBO = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeBO]; }]; [TPUserDefault instance].offlineList = [NSArray arrayWithArray:tempArray]; } }]; } } return userDefaultsInstance; } - (NSString*)getContollerNameWithNodeId:(NSString*)nodeId { if ([nodeId isEqualToString:@"25949"]) { return @"channalCollectController"; }else if ([nodeId isEqualToString:@"25950"]) { return @"channalPoliticsController"; }else if ([nodeId isEqualToString:@"25951"]) { return @"channalEconomyController"; }else if ([nodeId isEqualToString:@"25952"]) { return @"channalInsightsController"; }else if ([nodeId isEqualToString:@"25953"]) { return @"channalLifeController"; }else if ([nodeId isEqualToString:@"-3"]) { return @"channalTopicController"; }else { return @"channalMyPaperController"; } } - (id)init { if (self = [super init]) { self.isOffline = NO; self.registerBO = [[registerInfoBO alloc]init]; self.fogetPwdInfoBO = [[registerInfoBO alloc]init]; self.imageQueue = [[NSOperationQueue alloc]init]; self.imageQueue.maxConcurrentOperationCount = 1; self.globalQueue = [[NSOperationQueue alloc]init]; self.globalQueue.maxConcurrentOperationCount = 1; defaults = [NSUserDefaults standardUserDefaults]; self.currentPageIndex = 0; NSString *isFirstIntoAppStr = [defaults objectForKey:@"isFirstIntoApp"]; self.isFirstIntoApp = isFirstIntoAppStr; NSString *version = [defaults objectForKey:@"appVersion"]; self.appVersion = version; NSString *uuidStr = [defaults objectForKey:@"uuid"]; self.uuid = uuidStr; NSString *isOpen = [defaults objectForKey:@"isOpenPush"]; if (!isOpen) { isOpen = @"1"; } /** * bug:6091(【适配性】ios9:设置通知栏里找不到澎湃新闻) */ self.isOpenPush = isOpen; NSString *fontSize = [defaults objectForKey:@"contentFontSize"]; if (isBlankString(fontSize)) { self.contFontSize = fontSizeMiddle; }else { self.contFontSize = [fontSize floatValue]; } NSDictionary *userDic = [defaults objectForKey:@"userBO"]; if (userDic) { self.userBO = setJsonDicToDataModel(userDic, [userBO class]); } NSString *readModeString = [defaults objectForKey:@"readMode"]; if (readModeString && !isBlankString(readModeString)) { self.readModeStr = readModeString; } NSString *noMore = [defaults objectForKey:@"noMoreReadMode"]; self.noMoreReadModeAlert = noMore; NSString *attion = [defaults objectForKey:@"isAttention"]; self.isAttention = attion; NSMutableArray *channelData = [defaults objectForKey:@"channelData"]; if (channelData && channelData.count > 0) { self.channldataList = [NSMutableArray array]; self.channldataList = channelData; } self.isUseSystemFont = [defaults objectForKey:@"isUserSystemFont"]; if (!self.isUseSystemFont) { self.isUseSystemFont = @"1"; } self.isNightMode = [defaults objectForKey:@"isNightMode"]; if (!self.isNightMode) { self.isNightMode = @"0"; } self.ignoreVersion = [defaults objectForKey:@"ignoreVersion"]; if (!self.ignoreVersion) { self.ignoreVersion = @"0"; } self.visitTime = [defaults objectForKey:@"visitTime"]; if (!self.visitTime) { self.visitTime = @"0"; } self.pauseDataDic = [defaults objectForKey:@"pauseDataDic"]; if (!self.pauseDataDic) { self.pauseDataDic = [NSMutableDictionary dictionary]; } self.helpArray = [defaults objectForKey:@"isFirstHelp"]; if (!self.helpArray) { NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:@"0" forKey:@"front"]; [dic setObject:@"0" forKey:@"detail"]; [dic setObject:@"0" forKey:@"order"]; self.helpArray = dic; } self.searchHistoryArray = [defaults objectForKey:@"searchHistoryArray"]; if (!self.searchHistoryArray) { self.searchHistoryArray = [NSMutableArray array]; } self.localCollectArray = [defaults objectForKey:@"localCollectArray"]; if (!self.localCollectArray) { self.localCollectArray = [NSMutableArray array]; } self.memoryPointArray = [defaults objectForKey:@"memoryPointArray"]; if (!self.memoryPointArray) { self.memoryPointArray = [NSMutableArray array]; } self.videoDefinition = [defaults objectForKey:@"videoDefinition"]; if (!self.videoDefinition) { self.videoDefinition = @"standard"; } NSString *registedPush = [defaults objectForKey:@"isRegistedPush"]; if (!self.isRegistedPush) { self.isRegistedPush = @"0"; } self.isRegistedPush = registedPush; self.offlineList = [NSMutableArray array]; self.offlineStatusList = [NSMutableArray array]; NSArray* offlineStatusArray = [defaults objectForKey:@"offlineStatusList"]; if (offlineStatusArray && offlineStatusArray.count > 0) { self.offlineStatusList = offlineStatusArray; } self.hotAskColorList = [NSArray arrayWithObjects:@{@"color":[UIColor colorWithHexString:@"0x7bc0e8"],@"image":@"other/color_1.png"}, @{@"color":[UIColor colorWithHexString:@"0x82c2cf"],@"image":@"other/color_2.png"}, @{@"color":[UIColor colorWithHexString:@"0x8c98cb"],@"image":@"other/color_3.png"}, @{@"color":[UIColor colorWithHexString:@"0xd7a36d"],@"image":@"other/color_4.png"}, @{@"color":[UIColor colorWithHexString:@"0xd28484"],@"image":@"other/color_5.png"},nil]; self.orderEventTempList = [NSMutableArray array]; if ([deviceString() isMatchedByRegex:@"iPhone 4"]) { self.isIphone4 = @"1"; }else { self.isIphone4 = @"0"; } } return self; } - (void)setPauseDataDic:(NSMutableDictionary *)dic { _pauseDataDic = dic; if (dic.allKeys.count==0) { [defaults setObject:nil forKey:@"pauseDataDic"]; [defaults synchronize]; }else { [defaults setObject:dic forKey:@"pauseDataDic"]; [defaults synchronize]; } } -(void)setHelpArray:(NSMutableDictionary *)array{ _helpArray = array; [defaults setObject:_helpArray forKey:@"isFirstHelp"]; [defaults synchronize]; } - (NSString*)deviceResolution { if (!_deviceResolution) { CGFloat scale_screen = [UIScreen mainScreen].scale; CGFloat width = rect_screen.size.width*scale_screen; CGFloat height = rect_screen.size.height*scale_screen; _deviceResolution = [NSString stringWithFormat:@"%.f*%.f",width,height]; } return _deviceResolution; } - (NSString*)systemInfo { if (!_systemInfo) { _systemInfo = [[UIDevice currentDevice] systemVersion]; } return _systemInfo; } - (void)setAppVersion:(NSString *)version { if (version && !isBlankString(version)) { _appVersion = version; [defaults setObject:version forKey:@"appVersion"]; [defaults synchronize]; } } - (NSString*)getappVer { NSDictionary* plistInfo = [NSDictionary dictionaryWithContentsOfFile:ResourcePath(@"Info.plist")]; // return [plistInfo objectForKey:@"CFBundleVersion"]; NSString *version = [plistInfo objectForKey:@"CFBundleShortVersionString"]; return version; } - (NSString*)IDFA { if (!_IDFA) { _IDFA = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; } return _IDFA; } - (void)setIsFirstIntoApp:(NSString *)isFirstIntoAppStr { if (isFirstIntoAppStr && !isBlankString(isFirstIntoAppStr)) { _isFirstIntoApp = isFirstIntoAppStr; [defaults setObject:isFirstIntoAppStr forKey:@"isFirstIntoApp"]; [defaults synchronize]; } } - (void)setContFontSize:(CGFloat)size { self.lastContentOffset = CGPointZero; [defaults setObject:[NSString stringWithFormat:@"%f",size] forKey:@"contentFontSize"]; [defaults synchronize]; CGFloat resize = [iphoneLineSpaceAndParaSpace resizeFontWithDifDevice:size]; _contFontSize = resize; } - (void) setUuid:(NSString *)uuidStr { if (uuidStr && !isBlankString(uuidStr)) { _uuid = uuidStr; [defaults setObject:uuidStr forKey:@"uuid"]; [defaults synchronize]; }else { CFUUIDRef puuid = CFUUIDCreate( nil ); CFStringRef uuidString = CFUUIDCreateString( nil, puuid ); NSString * result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString)); CFRelease(puuid); CFRelease(uuidString); _uuid = result; [defaults setObject:result forKey:@"uuid"]; [defaults synchronize]; } } - (void)setUserBO:(userBO *)data { _userBO = data; if (data) { NSDictionary *dic = setDataModelToDic(data, [userBO class]); [defaults setObject:dic forKey:@"userBO"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"userBO"]; [defaults synchronize]; } } - (void)setReadModeStr:(NSString *)str { _readModeStr = str; [[NSNotificationCenter defaultCenter]postNotificationName:NEEDREFRESHCHANGEREADMODE object:nil]; if (str && !isBlankString(str)) { [defaults setObject:str forKey:@"readMode"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"readMode"]; [defaults synchronize]; } } - (void)setNoMoreReadModeAlert:(NSString *)str { _noMoreReadModeAlert = str; if (str && !isBlankString(str)) { [defaults setObject:str forKey:@"noMoreReadMode"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"noMoreReadMode"]; [defaults synchronize]; } } - (void)setIsOpenPush:(NSString *)isOpen { _isOpenPush = isOpen; if (isOpen) { [defaults setObject:isOpen forKey:@"isOpenPush"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"isOpenPush"]; [defaults synchronize]; } } - (void)setOfflineList:(NSArray *)list { _offlineList = list; if (list.count > 0) { NSArray* offlineStatusArray = [defaults objectForKey:@"offlineStatusList"]; if (!offlineStatusArray || offlineStatusArray.count == 0) { NSMutableArray *tempList = [NSMutableArray array]; [list enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL *stop) { NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setValue:obj.nodeId forKey:@"nodeId"]; [dic setValue:obj.name forKey:@"name"]; NSString* colorStr = [obj.color stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]; [dic setValue:colorStr forKey:@"color"]; [dic setValue:@"1" forKey:@"isSelected"]; [dic setValue:nil forKey:@"updateDate"]; [dic setValue:@"0" forKey:@"progressCompletion"]; [tempList addObject:dic]; }]; self.offlineStatusList = tempList; }else { self.offlineStatusList = offlineStatusArray; } } } - (void)setOfflineStatusList:(NSArray *)list { _offlineStatusList = list; if (list.count == 0) { return; } [defaults setObject:list forKey:@"offlineStatusList"]; [defaults synchronize]; } - (void)setChannldataList:(NSMutableArray *)list { _channldataList = list; [defaults setObject:list forKey:@"channelData"]; [defaults synchronize]; } - (void)setIsUseSystemFont:(NSString*)isUseSystem { _isUseSystemFont = isUseSystem; [defaults setObject:isUseSystem forKey:@"isUserSystemFont"]; [defaults synchronize]; } - (void)setIsNightMode:(NSString *)nightMode { _isNightMode = nightMode; [defaults setObject:nightMode forKey:@"isNightMode"]; [defaults synchronize]; } - (void)setMsgMark:(NSMutableDictionary *)msg { _msgMark = msg; AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; TPMainPageViewController *mainVC=[delegate mainVC]; if ([self isHaveUnMarkedMsg]) { [mainVC addBudgeViewInRightButton]; if (mainVC.menuView) { [mainVC.menuView refreshMsgMark]; } }else { [mainVC removeBudgeViewInRightButton]; if (mainVC.menuView) { [mainVC.menuView refreshMsgMark]; } } } -(void)setVisitTime:(NSString *)visitTime{ _visitTime = visitTime; [defaults setObject:visitTime forKey:@"visitTime"]; [defaults synchronize]; } - (void)setSearchHistoryArray:(NSMutableArray *)historyArray { _searchHistoryArray = historyArray; [defaults setObject:historyArray forKey:@"searchHistoryArray"]; [defaults synchronize]; } - (void)setLocalCollectArray:(NSMutableArray *)collectArray { _localCollectArray = collectArray; [defaults setObject:collectArray forKey:@"localCollectArray"]; [defaults synchronize]; } - (void)setMemoryPointArray:(NSMutableArray *)pointArray { _memoryPointArray = pointArray; [defaults setObject:pointArray forKey:@"memoryPointArray"]; [defaults synchronize]; } - (void)setVideoDefinition:(NSString *)videoDefinition { _videoDefinition = videoDefinition; [defaults setObject:videoDefinition forKey:@"videoDefinition"]; [defaults synchronize]; } - (BOOL)isHaveUnMarkedMsg { if (self.msgMark[@"status"] == 0 ||[self.msgMark[@"status"] intValue] == 0) { return NO; } __block BOOL isHaveUnMarked = NO; [self.msgMark.allKeys enumerateObjectsUsingBlock:^(NSString* key, NSUInteger idx, BOOL *stop) { if (![key isEqualToString:@"status"]) {//功能页,当我的消息-回复我的和私信中有新内容时,功能页右上角三横那里没有红点提示(bug:4817) if ([key isEqualToString:@"trackMark"] || [key isEqualToString:@"questionMark"]||[key isEqualToString:@"attendMark"] || [key isEqualToString:@"createdTopicMark"] || [key isEqualToString:@"attendTopicMark"] || [key isEqualToString:@"letterMark"] || [key isEqualToString:@"replyedMark"]) { if ([self.msgMark[key] longValue] > 0) { isHaveUnMarked = YES; *stop = YES; } } } }]; return isHaveUnMarked; } - (void)setPushBO:(remotePushBO *)push { if (_pushBO && [_pushBO.isComeFromRemote intValue] == 0 && [push.isComeFromRemote intValue] == 1) { return; } _pushBO = push; if (push) { [[NSNotificationCenter defaultCenter] postNotificationName:LINKWITHPUSH object:nil userInfo:nil]; } } - (void)setIgnoreVersion:(NSString *)version { _ignoreVersion = version; if (version) { [defaults setObject:version forKey:@"ignoreVersion"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"ignoreVersion"]; [defaults synchronize]; } } - (void)setIsRegistedPush:(NSString *)push { _isRegistedPush = push; if (push) { [defaults setObject:push forKey:@"isRegistedPush"]; [defaults synchronize]; }else { [defaults setObject:nil forKey:@"isRegistedPush"]; [defaults synchronize]; } } - (NSString*)deviceUA { if (!_deviceUA) { NSString *userAgent = [[[UIWebView alloc] init] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; // NSString *appName = NSLocalizedStringFromTable(@"CFBundleDisplayName", @"InfoPlist", nil); NSString * appName = [[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"]; NSString *version = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"]; NSString *customUserAgent = [userAgent stringByAppendingFormat:@" %@/%@", appName, version]; _deviceUA = customUserAgent; } return _deviceUA; } -(NSString *)hostId{ if (!_hostId) { _hostId = @""; } return _hostId; } - (void)clearCache:(id)sender { if (sender) { [self performSelectorOnMainThread:@selector(showClearStatus:) withObject:sender waitUntilDone:YES]; } [[CoreDataManager shareInstance] deleteCoreDataFile];//解决版本更新数据库闪退(bug fixed:4587) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:CachePath(@"")]; NSLog(@"files: %ld",(long)files.count); for (NSString *p in files) { NSError *error; NSString *path = [CachePath(@"") stringByAppendingString:p]; if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; } } [self performSelectorOnMainThread:@selector(showSuccessStatus:) withObject:sender waitUntilDone:YES]; }); } - (void)clearCache { [[CoreDataManager shareInstance] deleteCoreDataFileWhenUpdate]; //解决版本更新数据库闪退(bug fixed:4587) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:CachePath(@"")]; NSLog(@"files: %ld",(long)files.count); for (NSString *p in files) { NSError *error; NSString *path = [CachePath(@"") stringByAppendingString:p]; if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; } } }); } - (void)showClearStatus:(id)sender { // ShowTextMessage(@"正在清理缓存..."); self.clearStatus = @"1"; if (sender) { if ([sender respondsToSelector:@selector(updateCacheText:)]) { [sender performSelectorOnMainThread:@selector(updateCacheText:) withObject:@"1" waitUntilDone:YES]; } } } - (void)showSuccessStatus:(id)sender { // ShowTextMessage(@"缓存清理成功!"); self.clearStatus = @"0"; if (sender) { if ([sender respondsToSelector:@selector(updateCacheText:)]) { [sender performSelectorOnMainThread:@selector(updateCacheText:) withObject:@"0" waitUntilDone:YES]; }else { dispatch_async(dispatch_get_main_queue(), ^{ ShowMessage(@"清理成功", YES); }); } }else { dispatch_async(dispatch_get_main_queue(), ^{ ShowMessage(@"清理成功", YES); }); } } - (void)dismissStatus { // [KGStatusBar dismiss]; } - (void)checkMsgMarkStatus { if (!self.userBO) { return; } [Remote doJsonActionWithBlock:0 requestUrl:getMsgMarkURL parameter:nil withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { self.msgMark = responseData[@"data"]; }else { ShowTextMessage(message); } }]; } - (void)setIsAttention:(NSString *)obj { _isAttention = obj; [defaults setObject:obj forKey:@"isAttention"]; [defaults synchronize]; } - (void)checkOldVersionDataInConfigPath { NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:ConfigPath(wangdaVersionConfigPath)]; for (NSString *fileName in files) { if ([fileName isEqualToString:@"user.xml"]) { NSMutableDictionary *userInfoDic = [NSMutableDictionary dictionary]; NSMutableDictionary *weiboIdMap = [NSMutableDictionary dictionary]; NSString *userInfoString = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] encoding:NSUTF8StringEncoding error:nil]; NSArray *userInfoList = [userInfoString componentsMatchedByRegex:@"\\[&quot;\\w+?&quot;\\]=&quot;.*?&quot;"]; for (NSString *str in userInfoList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; NSRange range = [tmpStr rangeOfString:@"="]; NSString *keyStr = [tmpStr substringToIndex:NSMaxRange(range)-1]; NSString *valueStr = [tmpStr substringFromIndex:NSMaxRange(range)]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; if ([keyStr isEqualToString:@"SINA"] || [keyStr isEqualToString:@"TENCENT"] || [keyStr isEqualToString:@"WEIXIN"] || [keyStr isEqualToString:@"QQCONTACT"] || [keyStr isEqualToString:@"QQZONE"] || [keyStr isEqualToString:@"PENGYOUQUAN"] || [keyStr isEqualToString:@"RENREN"] || [keyStr isEqualToString:@"SOHU"]) [weiboIdMap setObject:valueStr forKey:keyStr]; else [userInfoDic setObject:valueStr forKey:keyStr]; } userInfoList = [userInfoString componentsMatchedByRegex:@"\\[&quot;\\w+?&quot;\\]=\\d+"]; for (NSString *str in userInfoList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; tmpStr = [tmpStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; tmpStr = [tmpStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; NSArray *tmpDic = [tmpStr componentsSeparatedByString:@"="]; [userInfoDic setObject:tmpDic[1] forKey:tmpDic[0]]; } NSLog(@"%@", userInfoDic); NSLog(@"%@", weiboIdMap); if ([[userInfoDic objectForKey:@"isLogin"] isEqualToString:@"1"]) { NSLog(@"login"); userBO *user = [userBO new]; user.area = userInfoDic[@"area"]; user.birthday = @""; user.blood = userInfoDic[@"blood"]; user.constellation = userInfoDic[@"constellation"]; user.endTime = @""; user.isAuth = userInfoDic[@"isAuth"]; user.isFree = @""; user.isSetPwd = userInfoDic[@"isSetPwd"]; user.mail = userInfoDic[@"mail"]; user.mobile = userInfoDic[@"mobile"]; user.name = userInfoDic[@"name"]; user.password = userInfoDic[@"password"]; user.perDesc = userInfoDic[@"perDesc"]; user.pic = userInfoDic[@"userPicSrc"]; user.profession = userInfoDic[@"profession"]; user.sex = userInfoDic[@"sex"]; user.sname = userInfoDic[@"sname"]; user.token = userInfoDic[@"token"]; user.userId = userInfoDic[@"userId"]; if ([userInfoDic[@"isSocialLogin"] isEqualToString:@"0"]) user.loginType = @"-1"; else if ([userInfoDic[@"isSocialLogin"] isEqualToString:@"SINA"]) user.loginType = @"2"; else if ([userInfoDic[@"isSocialLogin"] isEqualToString:@"TENCENT"]) user.loginType = @"9"; else if ([userInfoDic[@"isSocialLogin"] isEqualToString:@"DOUBAN"]) user.loginType = @"20"; else if ([userInfoDic[@"isSocialLogin"] isEqualToString:@"WEIXIN"]) user.loginType = @"1"; user.weiboIdMap = weiboIdMap; [TPUserDefault instance].userBO = user; } else NSLog(@"no login"); [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } else if ([fileName isEqualToString:@"setting.xml"]) { NSMutableDictionary *settingInfoDic = [NSMutableDictionary dictionary]; NSString *settingInfoString = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] encoding:NSUTF8StringEncoding error:nil]; NSArray *settingInfoList = [settingInfoString componentsMatchedByRegex:@"\\[&quot;\\w+?&quot;\\]=&quot;.*?&quot;"]; for (NSString *str in settingInfoList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; NSRange range = [tmpStr rangeOfString:@"="]; NSString *keyStr = [tmpStr substringToIndex:NSMaxRange(range)-1]; NSString *valueStr = [tmpStr substringFromIndex:NSMaxRange(range)]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; [settingInfoDic setObject:valueStr forKey:keyStr]; } settingInfoList = [settingInfoString componentsMatchedByRegex:@"\\[&quot;\\w+?&quot;\\]=\\d+"]; for (NSString *str in settingInfoList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; tmpStr = [tmpStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; tmpStr = [tmpStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; NSArray *tmpDic = [tmpStr componentsSeparatedByString:@"="]; [settingInfoDic setObject:tmpDic[1] forKey:tmpDic[0]]; } if ([settingInfoDic[@"isPicMode"] isEqualToString:@"1"]) [TPUserDefault instance].readModeStr = @"0"; if ([settingInfoDic[@"isSmartMode"] isEqualToString:@"1"]) [TPUserDefault instance].readModeStr = @"2"; if ([settingInfoDic[@"isPicMode"] isEqualToString:@"0"] && [settingInfoDic[@"isSmartMode"] isEqualToString:@"0"]) [TPUserDefault instance].readModeStr = @"1"; if (!isBlankString(settingInfoDic[@"isNightMode"])) [TPUserDefault instance].isNightMode = settingInfoDic[@"isNightMode"]; if (!isBlankString(settingInfoDic[@"pushMsg"])) [TPUserDefault instance].isOpenPush = settingInfoDic[@"pushMsg"]; if (!isBlankString(settingInfoDic[@"fontSizeLevel"])) { if ([settingInfoDic[@"fontSizeLevel"] isEqualToString:@"1"]) [TPUserDefault instance].contFontSize = fontSizeExSmall; if ([settingInfoDic[@"fontSizeLevel"] isEqualToString:@"2"]) [TPUserDefault instance].contFontSize = fontSizeSmall; if ([settingInfoDic[@"fontSizeLevel"] isEqualToString:@"3"]) [TPUserDefault instance].contFontSize = fontSizeMiddle; if ([settingInfoDic[@"fontSizeLevel"] isEqualToString:@"4"]) [TPUserDefault instance].contFontSize = fontSizeBig; if ([settingInfoDic[@"fontSizeLevel"] isEqualToString:@"5"]) [TPUserDefault instance].contFontSize = fontSizeExBig; } if (!isBlankString(settingInfoDic[@"fontFamily"])) //bug5983: 升级:网达app覆盖升级成原生app,搜索历史和字体没有保留 [TPUserDefault instance].isUseSystemFont = settingInfoDic[@"fontFamily"]; NSLog(@"%@", settingInfoDic); [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } else if ([fileName isEqualToString:@"channelnodeid.xml"]) { NSMutableArray *channelNodeId = [NSMutableArray array]; NSString *channelInfoString = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] encoding:NSUTF8StringEncoding error:nil]; NSArray *channelInfoList = [channelInfoString componentsMatchedByRegex:@"\\[\\d+\\]=&quot;.*?&quot;"]; NSMutableDictionary *channelNodeIdDic = [NSMutableDictionary dictionary]; for (NSString *str in channelInfoList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; NSRange range = [tmpStr rangeOfString:@"="]; NSString *keyStr = [tmpStr substringToIndex:NSMaxRange(range)-1]; NSString *valueStr = [tmpStr substringFromIndex:NSMaxRange(range)]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; [channelNodeIdDic setObject:valueStr forKey:keyStr]; } for (int i=0; i<7; i++) { if (!isBlankString(channelNodeIdDic[[NSString stringWithFormat:@"%d",i]])) [channelNodeId addObject:channelNodeIdDic[[NSString stringWithFormat:@"%d",i]]]; } if (channelNodeId.count == 7) { [Remote doJsonActionWithBlock:0 requestUrl:allNodeListURL parameter:nil withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success && responseData[@"nodeList"]) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; NSMutableDictionary *nodeDic = [NSMutableDictionary dictionary]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSString *nodeID = obj[@"nodeId"]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:obj]; [dic setValue:[self getContollerNameWithNodeId:nodeID] forKey:@"controller"]; NSString *color = dic[@"color"]; color = [color substringWithRange:NSMakeRange(1, 6)]; color = [NSString stringWithFormat:@"0x%@",color]; [dic setValue:color forKey:@"color"]; [nodeDic setObject:dic forKey:nodeID]; }]; for (NSString *nodeId in channelNodeId) { [tempArray addObject:nodeDic[nodeId]]; } if (tempArray.count == 7) { [TPUserDefault instance].channldataList = tempArray; //bug5979: 升级:网达app覆盖升级成原生app,离线阅读页面错乱 NSDictionary *dic = @{@"type":@"4"}; [Remote doJsonActionWithBlock:2 requestUrl:allNodeListURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (responseData && responseData[@"nodeList"]) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeBO = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeBO]; }]; [TPUserDefault instance].offlineList = [NSArray arrayWithArray:tempArray]; } }]; } } }]; } NSLog(@"%@", channelNodeId); [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } else if ([fileName isEqualToString:@"favorite.xml"]) { NSMutableArray *collectArray = [NSMutableArray array]; NSString *collectString = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] encoding:NSUTF8StringEncoding error:nil]; NSArray *collectList = [collectString componentsMatchedByRegex:@"<Item name=\"\\d+\" value=\".*?\" />"]; for (NSString *str in collectList) { NSMutableDictionary *collectDic = [NSMutableDictionary dictionary]; NSArray *collectInfoList = [str componentsMatchedByRegex:@"\\[&quot;\\w+?&quot;\\]=&quot;.*?&quot;"]; for (NSString *info in collectInfoList) { NSString *tmpStr = [info stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; NSRange range = [tmpStr rangeOfString:@"="]; NSString *keyStr = [tmpStr substringToIndex:NSMaxRange(range)-1]; NSString *valueStr = [tmpStr substringFromIndex:NSMaxRange(range)]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; [collectDic setObject:valueStr forKey:keyStr]; } if (collectDic.count == 4) { [collectArray addObject:collectDic]; } } if (collectArray.count) { [TPUserDefault instance].localCollectArray = collectArray; } [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } else if ([fileName isEqualToString:@"searchHistory.xml"]) { //bug5983: 升级:网达app覆盖升级成原生app,搜索历史和字体没有保留 NSMutableDictionary *historyDic = [NSMutableDictionary dictionary]; NSString *historyString = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] encoding:NSUTF8StringEncoding error:nil]; NSArray *historyList = [historyString componentsMatchedByRegex:@"\\[\\d+\\]=&quot;.+?&quot;"]; for (NSString *str in historyList) { NSString *tmpStr = [str stringByReplacingOccurrencesOfRegex:@"&quot;" withString:@""]; NSRange range = [tmpStr rangeOfString:@"="]; NSString *keyStr = [tmpStr substringToIndex:NSMaxRange(range)-1]; NSString *valueStr = [tmpStr substringFromIndex:NSMaxRange(range)]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\[" withString:@""]; keyStr = [keyStr stringByReplacingOccurrencesOfRegex:@"\\]" withString:@""]; [historyDic setObject:valueStr forKey:keyStr]; } NSMutableArray *historyArray = [NSMutableArray array]; for (int i=1; i<=10; i++) { if (!isBlankString(historyDic[[NSString stringWithFormat:@"%d",i]])) [historyArray addObject:historyDic[[NSString stringWithFormat:@"%d",i]]]; } for (NSString *str in historyArray) [searchStrDB addOrUpdateSearchStr:str]; [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } else { [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", ConfigPath(wangdaVersionConfigPath), fileName] error:nil]; } } } @end