APPdelegateModularForRequest.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // APPdelegateModularForRequest.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2021/4/12.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "APPdelegateModularForRequest.h"
  9. #import "RQAppEventAnnotation.h"
  10. RQAppEventMod(APPdelegateModularForRequest)
  11. @implementation APPdelegateModularForRequest
  12. - (NSInteger)moduleLevel {
  13. return 1;
  14. }
  15. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  16. [self initMudule];
  17. // [self destroyModule];
  18. return YES;
  19. }
  20. - (void)initMudule {
  21. /// 获取广告相关
  22. [self getAppParam];
  23. /// 视频接口相关
  24. [self getVideoTypeList];
  25. /// 同步本地数据
  26. [UserInfo shareInfo];
  27. [self getConfigKey];
  28. if (RQ_USER_MANAGER.currentUser) {
  29. myDelegate.isLogin = YES;
  30. }
  31. //默认科目一
  32. if (!myDelegate.subject) {
  33. myDelegate.subject = @"1";
  34. RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne;
  35. }
  36. //异步获取新的广告
  37. [jiaPeiManager requestADImage];
  38. //判断跳转页面 这样每次更新版本 都会有导航页
  39. NSString *vesionNow = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  40. // if (![RQ_COMMON_MANAGER.isWelcomed isEqualToString:vesionNow]) {
  41. // [[NSUserDefaults standardUserDefaults] setBool:NO forKey:BOOLFORKEY];
  42. // RQ_COMMON_MANAGER.isWelcomed = vesionNow;
  43. // //如果更新了数据库 运行的时候要加上下面这句代码 提取旧库数据 移除旧的数据库 重新copy到document文件目录下
  44. // [DB_Que_Helper getDataFormLastDB];
  45. // myDelegate.isSyn = YES;
  46. // } else {
  47. //
  48. // }
  49. }
  50. - (void)getAppParam {
  51. NSMutableArray *arr = [NSMutableArray array];
  52. [arr addPro:@"dqbh" Value:[NSString stringWithFormat:@"%@",RQ_USER_MANAGER.currentUser.city? : ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"(null)"]? @"" : @"")]];
  53. NSString *method= @"getAppParam";
  54. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  55. if ([dict[@"code"] isEqualToString:@"0"]) {
  56. if ([dict [@"body"] isKindOfClass:[NSArray class]]) {
  57. NSArray *array = dict [@"body"];
  58. [array.rac_sequence.signal subscribeNext:^(NSDictionary *dic) {
  59. [RQ_SHARE_FUNCTION saveObjectWithObject:dic[@"VALUE"] ForKey:dic[@"KEY"]];
  60. }];
  61. }
  62. }
  63. }];
  64. }
  65. - (void)getVideoTypeList {
  66. [[RQ_HTTP_Service getTreeList] subscribeNext:^(NSArray <RQTreeListModel *> * dataArr) {
  67. if (!RQObjectIsNil(dataArr)) {
  68. RQ_COMMON_MANAGER.treeListArr = dataArr;
  69. }
  70. }];
  71. [[RQ_HTTP_Service getDspListWithPageNum:1 pageSize:10] subscribeNext:^(NSArray <VideosItem *> * videosItemArr) {
  72. if (!RQObjectIsNil(videosItemArr)) {
  73. RQ_COMMON_MANAGER.dspListArr = videosItemArr;
  74. }
  75. }];
  76. }
  77. - (void)getAppStoreVersionWithComplete:(VoidBlock_integer)complete {
  78. NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1214200225";
  79. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
  80. [request setHTTPMethod:@"POST"];
  81. NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  82. dispatch_async_on_main_queue(^{
  83. //这个导致部分手机网络不好时候出现闪退情况
  84. if (!data) {
  85. complete(0);
  86. return;
  87. }
  88. //如果data等于nil的时候 再去解析 会发生崩溃
  89. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  90. if (!dic) {
  91. complete(0);
  92. return;
  93. }
  94. NSArray *infoArray = [dic objectForKey:@"results"];
  95. if ([infoArray count]) {
  96. NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
  97. NSString *netVersion = [releaseInfo objectForKey:@"version"];
  98. // 线上版本号
  99. NSInteger netInt = [[netVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  100. complete(netInt);
  101. } else {
  102. complete(0);
  103. }
  104. });
  105. }];
  106. [task resume];
  107. }
  108. - (void)getConfigKey {
  109. NSInteger localVersion = [[RQ_APP_VERSION stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  110. [[RQ_HTTP_Service getJsjpSet] subscribeNext:^(NSArray *setArr) {
  111. [setArr.rac_sequence.signal subscribeNext:^(RQDictInfoModel *dictInfoModel) {
  112. if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_OPEN"]) {
  113. RQ_COMMON_MANAGER.JSJP_APP_AD_OPEN = [[NSString stringWithFormat:@"%@",dictInfoModel.dictValue] isEqualToString:@"1"]? YES : NO;
  114. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_CYCLE"]) {
  115. RQ_COMMON_MANAGER.JSJP_APP_AD_CYCLE = [dictInfoModel.dictValue integerValue];
  116. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Is_Online_Media_Image"]) {
  117. RQ_COMMON_MANAGER.JSJP_Is_Online_Media_Image = [dictInfoModel.dictValue boolValue];
  118. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Is_Online_Media_Video"]) {
  119. RQ_COMMON_MANAGER.JSJP_Is_Online_Media_Video = [dictInfoModel.dictValue boolValue];
  120. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_Online_Version"]) {
  121. NSInteger customOnlineVersion = [[[NSString stringWithFormat:@"%@",dictInfoModel.dictValue] stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  122. RQ_COMMON_MANAGER.APP_SWITCH = (localVersion >= customOnlineVersion);
  123. RQ_COMMON_MANAGER.APP_SWITCH = NO;
  124. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_ICON_NEED_CHANGE"]) {
  125. RQ_COMMON_MANAGER.JSJP_APP_ICON_NEED_CHANGE = [dictInfoModel.dictValue boolValue];
  126. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_AD_RATE"]) {
  127. RQ_COMMON_MANAGER.JSJP_APP_AD_RATE = [dictInfoModel.dictValue integerValue];
  128. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_PTSC_FBL"]) {
  129. RQ_COMMON_MANAGER.JSJP_APP_PTSC_FBL = dictInfoModel.dictValue;
  130. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_DOMIAN_NAME_IS_OLD"]) {
  131. RQ_COMMON_MANAGER.JSJP_DOMIAN_NAME_IS_OLD = [dictInfoModel.dictValue boolValue];
  132. } else if ([dictInfoModel.dictLabel isEqualToString:@"JSJP_APP_KAOCHANG_OPEN_ARR"]) {
  133. RQ_COMMON_MANAGER.JSJP_APP_KAOCHANG_OPEN_ARR = [dictInfoModel.remark componentsSeparatedByString:@","];
  134. }
  135. }];
  136. }];
  137. [[RQ_HTTP_Service getChapterList] subscribeNext:^(id _Nullable x) {
  138. }];
  139. // [[RQ_HTTP_Service getConfigKeyWithDictType:@"Online_Version"] subscribeNext:^(id _Nullable x) {
  140. // NSInteger customOnlineVersion = [[[NSString stringWithFormat:@"%@",x] stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  141. // /// 本地版本大于等于内部版本(审核的时候本地版本一定等于内部版本,上线后本地版本一定小余内部版本)
  142. // RQ_COMMON_MANAGER.APP_SWITCH = localVersion >= customOnlineVersion;
  143. // } error:^(NSError * _Nullable error) {
  144. // [self getAppStoreVersionWithComplete:^(NSInteger onlineVersion) {
  145. // if (onlineVersion != 0) {
  146. // /// 本地版本大于线上版本(审核的时候本地版本一定大于线上版本,上线后本地版本一定等于线上版本(有延迟...所以作为备选方案))
  147. // RQ_COMMON_MANAGER.APP_SWITCH = localVersion > onlineVersion;
  148. // } else {
  149. // RQ_COMMON_MANAGER.APP_SWITCH = NO;
  150. // }
  151. // }];
  152. // }];
  153. }
  154. @end