// // APPdelegateModularForRequest.m // jiaPei // // Created by 张嵘 on 2021/4/12. // Copyright © 2021 JCZ. All rights reserved. // #import "APPdelegateModularForRequest.h" #import "RQAppEventAnnotation.h" RQAppEventMod(APPdelegateModularForRequest) @implementation APPdelegateModularForRequest - (NSInteger)moduleLevel { return 1; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self initMudule]; // [self destroyModule]; return YES; } - (void)initMudule { /// 获取广告相关 [self getAppParam]; /// 视频接口相关 [self getVideoTypeList]; /// 同步本地数据 [UserInfo shareInfo]; [self getConfigKey]; if (RQ_USER_MANAGER.currentUser) { myDelegate.isLogin = YES; } //默认科目一 if (!myDelegate.subject) { myDelegate.subject = @"1"; RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne; } //异步获取新的广告 [jiaPeiManager requestADImage]; //判断跳转页面 这样每次更新版本 都会有导航页 NSString *vesionNow = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; // if (![RQ_COMMON_MANAGER.isWelcomed isEqualToString:vesionNow]) { // [[NSUserDefaults standardUserDefaults] setBool:NO forKey:BOOLFORKEY]; // RQ_COMMON_MANAGER.isWelcomed = vesionNow; // //如果更新了数据库 运行的时候要加上下面这句代码 提取旧库数据 移除旧的数据库 重新copy到document文件目录下 // [DB_Que_Helper getDataFormLastDB]; // myDelegate.isSyn = YES; // } else { // // } } - (void)getAppParam { NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"dqbh" Value:[NSString stringWithFormat:@"%@",RQ_USER_MANAGER.currentUser.city? : ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"(null)"]? @"" : @"")]]; NSString *method= @"getAppParam"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { if ([dict[@"code"] isEqualToString:@"0"]) { if ([dict [@"body"] isKindOfClass:[NSArray class]]) { NSArray *array = dict [@"body"]; [array.rac_sequence.signal subscribeNext:^(NSDictionary *dic) { [RQ_SHARE_FUNCTION saveObjectWithObject:dic[@"VALUE"] ForKey:dic[@"KEY"]]; }]; } } }]; } - (void)getVideoTypeList { [[RQ_HTTP_Service getTreeList] subscribeNext:^(NSArray * dataArr) { if (!RQObjectIsNil(dataArr)) { RQ_COMMON_MANAGER.treeListArr = dataArr; } }]; [[RQ_HTTP_Service getDspListWithPageNum:1 pageSize:10] subscribeNext:^(NSArray * videosItemArr) { if (!RQObjectIsNil(videosItemArr)) { RQ_COMMON_MANAGER.dspListArr = videosItemArr; } }]; } - (void)getAppStoreVersionWithComplete:(VoidBlock_integer)complete { NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1214200225"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10]; [request setHTTPMethod:@"POST"]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { dispatch_async_on_main_queue(^{ //这个导致部分手机网络不好时候出现闪退情况 if (!data) { complete(0); return; } //如果data等于nil的时候 再去解析 会发生崩溃 NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; if (!dic) { complete(0); return; } NSArray *infoArray = [dic objectForKey:@"results"]; if ([infoArray count]) { NSDictionary *releaseInfo = [infoArray objectAtIndex:0]; NSString *netVersion = [releaseInfo objectForKey:@"version"]; // 线上版本号 NSInteger netInt = [[netVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; complete(netInt); } else { complete(0); } }); }]; [task resume]; } - (void)getConfigKey { NSInteger localVersion = [[RQ_APP_VERSION stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; [[RQ_HTTP_Service getJsjpSet] subscribeNext:^(NSArray *setArr) { [setArr.rac_sequence.signal subscribeNext:^(RQDictInfoModel *dictInfoModel) { if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_OPEN"]) { RQ_COMMON_MANAGER.JSJP_APP_AD_OPEN = [[NSString stringWithFormat:@"%@",dictInfoModel.dictValue] isEqualToString:@"1"]? YES : NO; }else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_JSQ_ICON_OPEN"]) { RQ_COMMON_MANAGER.JSJP_APP_JSQ_ICON_OPEN = [[NSString stringWithFormat:@"%@",dictInfoModel.dictValue] isEqualToString:@"1"]? YES : NO; }else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_CYCLE"]) { RQ_COMMON_MANAGER.JSJP_APP_AD_CYCLE = [dictInfoModel.dictValue integerValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Is_Online_Media_Image"]) { RQ_COMMON_MANAGER.JSJP_Is_Online_Media_Image = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Is_Online_Media_Video"]) { RQ_COMMON_MANAGER.JSJP_Is_Online_Media_Video = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Online_Version"]) { NSInteger customOnlineVersion = [[[NSString stringWithFormat:@"%@",dictInfoModel.dictValue] stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; RQ_COMMON_MANAGER.APP_SWITCH = (localVersion >= customOnlineVersion); RQ_COMMON_MANAGER.APP_SWITCH = NO; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_ICON_NEED_CHANGE"]) { RQ_COMMON_MANAGER.JSJP_APP_ICON_NEED_CHANGE = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_RATE"]) { RQ_COMMON_MANAGER.JSJP_APP_AD_RATE = [dictInfoModel.dictValue integerValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_PTSC_FBL"]) { RQ_COMMON_MANAGER.JSJP_APP_PTSC_FBL = dictInfoModel.dictValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_DOMIAN_NAME_IS_OLD"]) { RQ_COMMON_MANAGER.JSJP_DOMIAN_NAME_IS_OLD = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_KAOCHANG_OPEN_ARR"]) { RQ_COMMON_MANAGER.JSJP_APP_KAOCHANG_OPEN_ARR = [dictInfoModel.remark componentsSeparatedByString:@","]; } }]; }]; [[RQ_HTTP_Service getChapterList] subscribeNext:^(id _Nullable x) { }]; // [[RQ_HTTP_Service getConfigKeyWithDictType:@"Online_Version"] subscribeNext:^(id _Nullable x) { // NSInteger customOnlineVersion = [[[NSString stringWithFormat:@"%@",x] stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; // /// 本地版本大于等于内部版本(审核的时候本地版本一定等于内部版本,上线后本地版本一定小余内部版本) // RQ_COMMON_MANAGER.APP_SWITCH = localVersion >= customOnlineVersion; // } error:^(NSError * _Nullable error) { // [self getAppStoreVersionWithComplete:^(NSInteger onlineVersion) { // if (onlineVersion != 0) { // /// 本地版本大于线上版本(审核的时候本地版本一定大于线上版本,上线后本地版本一定等于线上版本(有延迟...所以作为备选方案)) // RQ_COMMON_MANAGER.APP_SWITCH = localVersion > onlineVersion; // } else { // RQ_COMMON_MANAGER.APP_SWITCH = NO; // } // }]; // }]; } @end