AppDelegate.m 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. //
  2. // AppDelegate.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/2.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ChooseExLibVC.h"
  10. #import "ADView.h"
  11. #import "MyMsgVC.h"
  12. #import "NewsDetVC.h"
  13. #import "TopicVC.h"
  14. #import "AllCoachPlanVC.h"
  15. #import "Tools.h"
  16. #import "MyUINavigationController.h"
  17. #pragma mark MOB
  18. //分享
  19. //#import <ShareSDK/ShareSDK.h>
  20. //#import <ShareSDKConnector/ShareSDKConnector.h>
  21. //短信验证
  22. //#import <SMS_SDK/SMSSDK.h>
  23. #import "WXApiManager.h"
  24. //腾讯开放平台(对应QQ和QQ空间)SDK头文件
  25. //#import <TencentOpenAPI/TencentOAuth.h>
  26. //#import <TencentOpenAPI/QQApiInterface.h>
  27. //微信SDK头文件
  28. #import <WechatOpenSDK/WXApi.h>
  29. #import <WechatOpenSDK/WXApiObject.h>
  30. //微信支付器
  31. #import "payRequsestHandler.h"
  32. //支付
  33. #import <AlipaySDK/AlipaySDK.h>
  34. //bugly腾讯bug统计
  35. #import <Bugly/Bugly.h>
  36. #import <AFNetworking/AFNetworkActivityIndicatorManager.h>
  37. /// 百度人脸识别
  38. #import <IDLFaceSDK/IDLFaceSDK.h>
  39. #import "FaceParameterConfig.h"
  40. #import "BDFaceAdjustParamsTool.h"
  41. #import "BDFaceLivingConfigModel.h"
  42. # if __has_include(<ABUAdSDK/ABUAdSDK.h>)
  43. #import <ABUAdSDK/ABUAdSDK.h>
  44. #else
  45. #import <Ads-Mediation-CN/ABUAdSDK.h>
  46. #endif
  47. #import <AppTrackingTransparency/AppTrackingTransparency.h>
  48. //#import <ABUVisualDebug/ABUVisualDebug.h>
  49. @interface AppDelegate ()<UIScrollViewDelegate,UIAlertViewDelegate,BMKGeneralDelegate,WXApiDelegate,GeTuiSdkDelegate, UNUserNotificationCenterDelegate,WXApiDelegate>
  50. {
  51. UIScrollView *scroll;
  52. NSString *pushType;
  53. NSString *pushID;
  54. UIPageControl *pageControl;
  55. }
  56. @property (assign , nonatomic) BOOL isShow;
  57. /// APP管理的导航栏的堆栈
  58. @property (nonatomic, readwrite, strong) RQNavigationControllerStack *navigationControllerStack;
  59. /// APP的服务层
  60. @property (nonatomic, readwrite, strong) RQViewModelServicesImpl *services;
  61. @property (nonatomic, assign, readwrite) AFNetworkReachabilityStatus networkReachabilityStatus;
  62. @end
  63. @implementation AppDelegate
  64. #pragma mark- 获取appDelegate
  65. + (AppDelegate *)sharedDelegate {
  66. return (AppDelegate *)[[UIApplication sharedApplication] delegate];
  67. }
  68. //程序开始
  69. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
  70. /// 初始化UI之前配置
  71. [self rq_configureApplication:application initialParamsBeforeInitUI:launchOptions];
  72. // Config Service
  73. self.services = [[RQViewModelServicesImpl alloc] init];
  74. // Config Nav Stack
  75. self.navigationControllerStack = [[RQNavigationControllerStack alloc] initWithServices:self.services];
  76. // Configure Window
  77. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  78. self.window.backgroundColor = [UIColor whiteColor];
  79. // 重置rootViewController
  80. [self.services resetRootViewModel:[self rq_createInitialViewModel]];
  81. // 让窗口可见
  82. [self.window makeKeyAndVisible];
  83. [RQ_CACHE_MANAGER removeAllCache];
  84. // 初始化UI后配置
  85. [self rq_configureApplication:application initialParamsAfterInitUI:launchOptions];
  86. #if defined(DEBUG)||defined(_DEBUG)
  87. /// 调试模式
  88. [self rq_configDebugModelTools];
  89. #endif
  90. // Save the application version info. must write last
  91. [[NSUserDefaults standardUserDefaults] setValue:RQ_APP_VERSION forKey:RQApplicationVersionKey];
  92. [[NSUserDefaults standardUserDefaults] synchronize];
  93. // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil];
  94. //获取沙盒
  95. //NSLog(@"沙盒-->%@",NSHomeDirectory());
  96. _isShow = NO;
  97. [self registerThirdSDK];
  98. //同步本地数据
  99. [UserInfo shareInfo];
  100. if (defUser.userDict) {
  101. _isLogin = YES;
  102. }
  103. //默认车型C1
  104. if (!defUser.car_type) {
  105. defUser.car_type = @"C1";
  106. RQ_YDTQuestion_Module.carType = RQHomePageCarType_Car;
  107. }
  108. //默认科目一
  109. if (!myDelegate.subject) {
  110. myDelegate.subject = @"1";
  111. RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne;
  112. }
  113. #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_10_0
  114. //这里即使不判断系统版本,后面也做了避免消息重复处理。didReceiveNotificationResponse 统一处理
  115. //远程通知
  116. if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey])
  117. {
  118. //关于这个方法远程和进程不一样 一个是userinfo字典。一个是本地通知
  119. NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  120. //这里不用判断重复消息
  121. NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1];
  122. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  123. [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"];
  124. [userDefaults synchronize];
  125. NSString *jsonStr = userInfo[@"payload"];
  126. if ([jsonStr length] != 0) {
  127. NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
  128. if (data) {
  129. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  130. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  131. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  132. //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关
  133. if ([pushType integerValue]>=1 && [pushType integerValue]<=6) {
  134. [self gotoPush];
  135. }else{
  136. //其它信息
  137. [self gotoLoad];
  138. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  139. }
  140. return YES;
  141. }
  142. }
  143. }
  144. #endif
  145. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  146. } else {
  147. //异步获取新的广告
  148. [jiaPeiManager requestADImage];
  149. }
  150. //判断跳转页面 这样每次更新版本 都会有导航页
  151. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  152. NSString *vesionNow = [infoDic objectForKey:@"CFBundleShortVersionString"];
  153. if (![defUser.isWelcomed isEqualToString:vesionNow]) {
  154. defUser.isWelcomed = vesionNow;
  155. // myDelegate.isSyn = YES;
  156. //要在这里清空数据库 如果版本需要更新数据库 可以在这里更新 不过 如果更新了 本地库里边保存的信息会不见 主要是miaxis.db这个库 里边有科目练习题
  157. //如果更新了新的数据库 第一次运行的时候要加上下面这句代码 移除旧的数据库 重新copy到document文件目录下
  158. //[DB_Que_Helper removeDB];
  159. [self makeLaunchView];
  160. }else{
  161. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  162. } else {
  163. if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) {
  164. if (RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN) {
  165. } else {
  166. //在这里搞个 广告页面 加载广告
  167. [ADView showADView];
  168. }
  169. }
  170. }
  171. [self gotoLoad];
  172. // 加载开屏广告
  173. // [self loadSplashAd];
  174. @try {
  175. [self onCheckVersion];
  176. }
  177. @catch (NSException *exception) {
  178. }
  179. @finally {
  180. }
  181. }
  182. /**微信支付
  183. 1、导入微信支付SDK,注册微信支付
  184. 2、设置微信appid为URL schemes
  185. 3、发起支付,调用微信支付
  186. 4、处理支付结果
  187. */
  188. [WXApi registerApp:WEIXIN_APPID universalLink:@"https://eqext.share2dlink.com/"];
  189. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  190. } else {
  191. /// 显示公告
  192. [self getAppAnnouncement];
  193. /// 显示硬性公告
  194. [self getAppAnnouncementOne];
  195. ///
  196. [self getAppCompetence];
  197. }
  198. SDImageWebPCoder*webPCoder = [SDImageWebPCoder sharedCoder];
  199. [[SDImageCodersManager sharedManager] addCoder:webPCoder];
  200. // [self test];
  201. // [self getVideoTypeList];
  202. // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil];
  203. /// 更新题库
  204. [RQ_Question_Module rq_updateQuestion];
  205. // [ABUVisualDebug startVisualDebug];
  206. [RQ_APPDELEGATE.window bringSubviewToFront:RQ_TIMING_VIEW];
  207. return YES;
  208. }
  209. //程序复原
  210. - (void)applicationDidBecomeActive:(UIApplication *)application{
  211. //删除程序小红点
  212. [GeTuiSdk resetBadge]; //重置角标计数
  213. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; //APP 清空角标
  214. if (myDelegate.timer) {
  215. [myDelegate.timer setFireDate:[NSDate distantPast]];
  216. }
  217. myDelegate.isBackgroundTask = NO;
  218. [RQ_TIMING_VIEW continueTiming];
  219. }
  220. //程序挂起
  221. - (void)applicationWillResignActive:(UIApplication *)application {
  222. }
  223. //程序进入后台
  224. - (void)applicationDidEnterBackground:(UIApplication *)application {
  225. if (myDelegate.timer) {//理论
  226. [myDelegate.timer setFireDate:[NSDate distantFuture]];
  227. }
  228. myDelegate.isBackgroundTask = YES;
  229. [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(){}];
  230. [RQ_TIMING_VIEW pauseTiming];
  231. }
  232. //程序到前台
  233. - (void)applicationWillEnterForeground:(UIApplication *)application {
  234. //[ADView showADView];
  235. }
  236. //程序意外退出
  237. - (void)applicationWillTerminate:(UIApplication *)application {
  238. //NSLog(@"程序退出"); 程序退出要将登录状态置为未登录状态
  239. }
  240. /// 应用处于后台,所有下载任务完成调用
  241. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
  242. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  243. appDelegate.backgroundSessionCompletionHandler = completionHandler;
  244. }
  245. #pragma mark 第三方sdk注册
  246. -(void)registerThirdSDK{
  247. //异常统计
  248. #ifdef DEBUG
  249. //do sth1.
  250. [Bugly startWithAppId:BUGLY_APP_ID];
  251. #else
  252. [Bugly startWithAppId:BUGLY_APP_ID];
  253. #endif
  254. //个推
  255. // 通过个推平台分配的appId、 appKey 、appSecret 启动SDK,注:该方法需要在主线程中调用
  256. [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self launchingOptions:nil];
  257. // 注册 APNs
  258. [self registerRemoteNotification];
  259. //初始化地图
  260. _mapManager = [[BMKMapManager alloc]init];
  261. // 如果要关注网络及授权验证事件,请设定 generalDelegate参数
  262. BOOL ret = [_mapManager start:BAIDU_APPKEY generalDelegate:self];
  263. if (!ret) {
  264. //NSLog(@"%d",ret);
  265. NSLog(@"manager start failed!");
  266. }
  267. //注册分享
  268. // [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
  269. // //QQ
  270. // [platformsRegister setupQQWithAppId:QQ_APPID appkey:QQ_APPKEY enableUniversalLink:NO universalLink:nil];
  271. //
  272. // //更新到4.3.3或者以上版本,微信初始化需要使用以下初始化
  273. // [platformsRegister setupWeChatWithAppId:WEIXIN_APPID appSecret:WEIXIN_APPSECRET universalLink:@"https://eqext.share2dlink.com/"];
  274. // }];
  275. //注册短信验证
  276. // [SMSSDK registerApp:SHARE_DX_APPKEY
  277. // withSecret:SHARE_DX_SCRECT];
  278. //注册分享
  279. // [ShareSDK registerApp:SHARE_FX_APPKEY
  280. //
  281. // activePlatforms:@[@(SSDKPlatformTypeCopy),
  282. // @(SSDKPlatformTypeWechat),
  283. // @(SSDKPlatformTypeQQ)]
  284. // onImport:^(SSDKPlatformType platformType)
  285. // {
  286. // switch (platformType)
  287. // {
  288. // case SSDKPlatformTypeWechat:
  289. // [ShareSDKConnector connectWeChat:[WXApi class]];
  290. // break;
  291. // case SSDKPlatformTypeQQ:
  292. // [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
  293. // break;
  294. // default:
  295. // break;
  296. // }
  297. // }
  298. // onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
  299. // {
  300. // switch (platformType)
  301. // {
  302. // case SSDKPlatformTypeWechat:
  303. // [appInfo SSDKSetupWeChatByAppId:WEIXIN_APPID
  304. // appSecret:WEIXIN_APPSECRET];
  305. // break;
  306. // case SSDKPlatformTypeQQ:
  307. // [appInfo SSDKSetupQQByAppId:QQ_APPID
  308. // appKey:QQ_APPKEY
  309. // authType:SSDKAuthTypeBoth];
  310. // break;
  311. // default:
  312. // break;
  313. // }
  314. // }];
  315. }
  316. #pragma mark 推送注册
  317. /** 注册 APNs */
  318. - (void)registerRemoteNotification {
  319. /*
  320. 警告:Xcode8及以上版本 需要手动开启"TARGETS -> Capabilities -> Push Notifications"
  321. */
  322. /*
  323. 警告:该方法需要开发者自定义,以下代码根据 APP 支持的 iOS 系统不同,代码可以对应修改。
  324. 以下为演示代码,注意根据实际需要修改,注意测试支持的 iOS 系统都能获取到 DeviceToken
  325. */
  326. if (iOS10) {
  327. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  328. center.delegate = self;
  329. [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
  330. if (!error) {
  331. NSLog(@"request authorization succeeded!(iOS >= 10.0)");
  332. }
  333. }];
  334. [[UIApplication sharedApplication] registerForRemoteNotifications];
  335. } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
  336. UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
  337. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
  338. [[UIApplication sharedApplication] registerForRemoteNotifications];
  339. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  340. } else {
  341. #pragma clang diagnostic push
  342. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  343. UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge);
  344. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
  345. #pragma clang diagnostic pop
  346. }
  347. }
  348. /** 远程通知注册成功委托 */
  349. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  350. NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
  351. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  352. NSLog(@"\n>>>[DeviceToken Success]:%@\n\n", token);
  353. // 向个推服务器注册deviceToken
  354. [GeTuiSdk registerDeviceToken:token];
  355. }
  356. /** 远程通知注册失败委托 */
  357. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  358. NSLog(@"FailToRegisterForRemoteNotificationsWithError:%@",error);
  359. }
  360. //iOS7.0 以后支持 APP 后台刷新数据,会回调 performFetchWithCompletionHandler 接口。为保证个推SDK的数据刷新,需在该回调接口中调用[GeTuiSdk resume]方法帮助个推 SDK 刷新数据。
  361. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  362. /// Background Fetch 恢复SDK 运行
  363. [GeTuiSdk resume];
  364. completionHandler(UIBackgroundFetchResultNewData);
  365. }
  366. #pragma mark - iOS < 10
  367. //处理 APNs 通知点击事件,统计有效用户点击数- (App运行在后台/App运行在前台) and apns静默推送消息处理
  368. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  369. NSLog(@"didReceiveRemoteNotification and iOS<10");
  370. // 将收到的APNs信息传给个推统计
  371. [GeTuiSdk handleRemoteNotification:userInfo];
  372. completionHandler(UIBackgroundFetchResultNewData);
  373. [self remoteNotificationDealWithDic:userInfo];
  374. }
  375. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  376. //接收到本地通知方法
  377. if (notification) {
  378. if (!_isShow) {
  379. [self showTheoryWindow];
  380. }
  381. }
  382. }
  383. - (void)showTheoryWindow {
  384. _isShow = YES;
  385. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"即将超过验证时间,请提前扫码验证" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:@[] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  386. _isShow = NO;
  387. }];
  388. }
  389. #pragma mark iOS > 10
  390. //对于iOS 10 及以后版本,为处理 APNs 通知点击,统计有效用户点击数,需先添加 UNUserNotificationCenterDelegate
  391. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  392. // iOS 10: App在前台获取到通知
  393. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  394. NSLog(@"willPresentNotification and iOS>10前台获取到通知:%@", notification.request.content.userInfo);
  395. if ([notification.request.identifier isEqualToString:@"Theory"]) {
  396. if (!_isShow) {
  397. [self showTheoryWindow];
  398. }
  399. }
  400. // 根据APP需要,判断是否要提示用户Badge、Sound、Alert
  401. completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
  402. }
  403. // iOS 10: 点击通知进入App时触发,在该方法内统计有效用户点击数
  404. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
  405. NSLog(@"didReceiveNotification and iOS>10后台获取到通知:%@", response.notification.request.content.userInfo);
  406. // [ GTSdk ]:将收到的APNs信息传给个推统计
  407. [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];
  408. completionHandler();
  409. if ([response.notification.request.identifier isEqualToString:@"Theory"]) {
  410. if (!_isShow) {
  411. [self showTheoryWindow];
  412. }
  413. }else {
  414. //此处表述程序由远程通知启动打开(不是点击桌面icon)
  415. NSDictionary* userInfo = response.notification.request.content.userInfo;
  416. [self remoteNotificationDealWithDic:userInfo];
  417. }
  418. }
  419. #endif
  420. #pragma mark - 个推相关方法
  421. /** SDK启动成功返回cid 在这里将cid给自己的服务器 */
  422. - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
  423. //个推SDK已注册,返回clientId
  424. NSLog(@"\n>>>[GeTuiSdk RegisterClient]:%@\n\n", clientId);
  425. //NSLog(@"获取推送token执行");
  426. myDelegate.token = clientId;
  427. NSString *tokenPass = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"apnsToken.plist"];
  428. if (![myDelegate.token writeToFile:tokenPass atomically:YES encoding:NSUTF8StringEncoding error:nil]) {
  429. NSLog(@"保存失败");
  430. }
  431. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  432. } else {
  433. upLoadToken();
  434. }
  435. //注册成功,将deviceToken保存到应用服务器数据库中
  436. // [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
  437. // stringByReplacingOccurrencesOfString:@">" withString:@""]
  438. // stringByReplacingOccurrencesOfString:@" " withString:@""]
  439. }
  440. /** SDK遇到错误回调 */
  441. - (void)GeTuiSdkDidOccurError:(NSError *)error {
  442. //个推错误报告,集成步骤发生的任何错误都在这里通知,如果集成后,无法正常收到消息,查看这里的通知。
  443. // NSLog(@"\n>>>[GexinSdk error]:%@\n\n", [error localizedDescription]);
  444. }
  445. /** SDK收到透传消息回调 *//*(个推-客户端)*/
  446. - (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
  447. //收到个推消息
  448. if (payloadData) {
  449. NSString * payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];
  450. NSLog(@"GeTuiSdkDidReceivepayloadMsg:%@",payloadMsg);
  451. //判断是否被处理过[即发送离线消息的时候,会走apns+个推sdk(有效期内)]
  452. //ps:这里处理之后不做存档操作,保证点击通知栏的时候可以”再处理一次“
  453. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  454. NSString *oldmsgId = [userDefaults objectForKey:@"remoteNotifymsgId"];
  455. if ([oldmsgId isEqualToString:msgId]) {
  456. return;
  457. }
  458. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:payloadData options:NSJSONReadingMutableContainers error:nil];
  459. if (payloadDic.count == 0) {
  460. return;
  461. }
  462. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  463. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  464. if ([pushType integerValue]>=1 && [pushType integerValue]<=5) {
  465. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:payloadDic[@"title"] message:payloadDic[@"body"] preferredStyle:UIAlertControllerStyleAlert];
  466. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  467. }]];
  468. [alertFind addAction:[UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  469. [self gotoPush];
  470. }]];
  471. [self.window.rootViewController presentViewController:alertFind animated:true completion:nil];
  472. }else{
  473. //其它信息
  474. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  475. }
  476. }
  477. }
  478. #pragma mark 远程通知的数据处理
  479. -(void)remoteNotificationDealWithDic:(NSDictionary *)userInfo{
  480. /*
  481. {
  482. "_ge_" = 1;
  483. "_gmid_" = "OSL-0818_bJ6zVRy8cC6JsflZOYPXO9:965f14a1051748c4a48f9db2437362e5:d48422d462d2bcf0b9d962f150b235b9";
  484. "_gurl_" = "sdk.open.extension.getui.com:8123";
  485. aps = {
  486. alert = {
  487. body = "\U60a8\U9a7e\U6821\U6709\U8f66\U8f86\U7ec8\U7aef\U62a5\U8b66\U9700\U89e3\U9664\Uff0c\U8bf7\U67e5\U770b\U5e76\U5904\U7406";
  488. title = "\U544a\U8b66\U6d88\U606f";
  489. };
  490. badge = 2;
  491. category = "button\U663e\U793a";
  492. "content-available" = 1;
  493. "mutable-content" = 1;
  494. sound = default;
  495. };
  496. payload = "{\"title\":\"\U544a\U8b66\U6d88\U606f\",\"code\":\"1\",\"body\":\"\U60a8\U9a7e\U6821\U6709\U8f66\U8f86\U7ec8\U7aef\U62a5\U8b66\U9700\U89e3\U9664\Uff0c\U8bf7\U67e5\U770b\U5e76\U5904\U7406\,\"id\":\"2\"}";
  497. }
  498. */
  499. // _gmid_对应-- taskId msgId clientID
  500. //这里使用msgid判断是否被处理【不过似乎应该用taskid?@lee,幻想着一个任务多条消息]
  501. NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1];
  502. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  503. NSString *oldMsgId = [userDefaults objectForKey:@"remoteNotifymsgId"];
  504. if ([msgId isEqualToString:oldMsgId]) {
  505. return;
  506. }
  507. //开始处理
  508. [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"];
  509. [userDefaults synchronize];
  510. NSString *jsonStr = userInfo[@"payload"];
  511. if ([jsonStr length] == 0) {
  512. return;
  513. }
  514. NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
  515. if (data) {
  516. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  517. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  518. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  519. //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关
  520. if ([pushType integerValue]>=1 && [pushType integerValue]<=5) {
  521. [self gotoPush];
  522. }else{
  523. //其它信息
  524. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  525. }
  526. }
  527. }
  528. -(void)showMsgByArertWithTitle:(NSString *)title message:(NSString *)message{
  529. if (message.length == 0) {
  530. return;
  531. }
  532. //其它信息
  533. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  534. [alertFind addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  535. }]];
  536. [self.window.rootViewController presentViewController:alertFind animated:true completion:nil];
  537. }
  538. #pragma mark 推送相关跳转
  539. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  540. {
  541. if (alertView.tag == 10000) {
  542. if (buttonIndex == 1) {
  543. NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/liao-ning-jia-pei/id1225178346?l=en&mt=8"];
  544. [[UIApplication sharedApplication]openURL:url];
  545. }
  546. }else{
  547. if (buttonIndex != alertView.cancelButtonIndex) {
  548. [self gotoPush];
  549. }
  550. }
  551. }
  552. -(void)gotoPush
  553. {
  554. //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关
  555. //新闻和驾考头条是一样的
  556. switch ([pushType integerValue]) {
  557. case 1:
  558. [self goToJKTT];
  559. break;
  560. case 2:
  561. [self goToJKTT];
  562. break;
  563. case 3:
  564. [self goToTopic];
  565. break;
  566. case 4:
  567. [self goToSystemNews];
  568. break;
  569. case 5:
  570. [self goToAppoint];
  571. break;
  572. case 6:
  573. [self gotoMyMessage];
  574. default:{
  575. [self gotoLoad];
  576. }
  577. break;
  578. }
  579. }
  580. -(void)goToJKTT
  581. {
  582. NewsDetVC* vc = [[NewsDetVC alloc] init];
  583. vc.jkttId = pushID;
  584. vc.type = @"1";
  585. vc.isNotification = YES;
  586. MyUINavigationController *nav = [[MyUINavigationController alloc]initWithRootViewController:vc];
  587. [myDelegate.window setRootViewController:nav];
  588. }
  589. -(void)goToSystemNews
  590. {
  591. MyMsgVC* vc = [[MyMsgVC alloc] init];
  592. vc.isNotification = YES;
  593. MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc];
  594. [myDelegate.window setRootViewController:navMsg];
  595. }
  596. -(void)goToTopic
  597. {
  598. TopicVC* vc = [[TopicVC alloc] init];
  599. [vc setTopicId:pushID];
  600. vc.isNotification = YES;
  601. MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc];
  602. [myDelegate.window setRootViewController:navMsg];
  603. }
  604. -(void)goToAppoint
  605. {
  606. AllCoachPlanVC *vc = [[AllCoachPlanVC alloc] init];
  607. vc.isNotification = YES;
  608. MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc];
  609. [myDelegate.window setRootViewController:navMsg];
  610. }
  611. -(void)gotoMyMessage{
  612. MyMsgVC* vc = [[MyMsgVC alloc] init];
  613. vc.isNotification = YES;
  614. MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:vc];
  615. [myDelegate.window setRootViewController:nav];
  616. }
  617. #pragma mark - 百度地图的代理
  618. - (void)onGetNetworkState:(int)iError
  619. {
  620. if (0 == iError) {
  621. }
  622. else{
  623. NSLog(@"联网失败");//有时候网络不好会触发这个,从而也同时引起授权失败
  624. }
  625. }
  626. - (void)onGetPermissionState:(int)iError
  627. {
  628. if (0 == iError) {
  629. }
  630. else {
  631. NSLog(@"授权失败");
  632. }
  633. }
  634. #pragma mark - 广告
  635. -(void)clickInADView
  636. {
  637. //去掉广告的代理在这里 页面传不过来 两个办法 一是将广告页面做成单例类 在这里关闭 二是这里发个通知或用kvo 在ADView中移除
  638. ADView *ad = [ADView shareMainAD];
  639. [ad removeImidiate];
  640. }
  641. #pragma mark WeChatPay
  642. - (void)onResp:(BaseResp *)resp {
  643. if([resp isKindOfClass:[PayResp class]]){
  644. //支付返回结果,实际支付结果需要去微信服务器端查询
  645. NSString *strMsg,*strTitle = [NSString stringWithFormat:@"支付结果"];
  646. switch (resp.errCode) {
  647. case WXSuccess:
  648. strMsg = @"支付结果:成功!";
  649. //NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
  650. break;
  651. default:
  652. strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
  653. //NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
  654. break;
  655. }
  656. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  657. [alert show];
  658. }
  659. }
  660. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  661. {
  662. //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  663. if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  664. return [WXApi handleOpenURL:url delegate:self];
  665. }
  666. //return [WXApi handleOpenURL:url delegate:self];
  667. return YES;
  668. }
  669. #pragma mark AliPay
  670. - (BOOL)application:(UIApplication *)application
  671. openURL:(NSURL *)url
  672. sourceApplication:(NSString *)sourceApplication
  673. annotation:(id)annotation {
  674. if ([url.host isEqualToString:@"safepay"]) {
  675. // 支付跳转支付宝钱包进行支付,处理支付结果
  676. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  677. NSLog(@"result = %@",resultDic);
  678. //NSLog(@"PaymentResult 支付结果11--><>%@",resultDic);
  679. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  680. //支付成功
  681. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  682. }else{
  683. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  684. }
  685. }];
  686. // 授权跳转支付宝钱包进行支付,处理支付结果
  687. [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
  688. NSLog(@"result = %@",resultDic);
  689. // 解析 auth code
  690. NSString *result = resultDic[@"result"];
  691. NSString *authCode = nil;
  692. if (result.length>0) {
  693. NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  694. for (NSString *subResult in resultArr) {
  695. if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  696. authCode = [subResult substringFromIndex:10];
  697. break;
  698. }
  699. }
  700. }
  701. NSLog(@"授权结果 authCode = %@", authCode?:@"");
  702. }];
  703. }
  704. //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  705. // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  706. // return [WXApi handleOpenURL:url delegate:self];
  707. // }
  708. return YES;
  709. }
  710. // NOTE: 9.0以后使用新API接口
  711. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
  712. {
  713. if ([url.host isEqualToString:@"safepay"]) {
  714. //跳转支付宝钱包进行支付,处理支付结果
  715. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  716. //NSLog(@"result 支付结果22--><>%@",resultDic);
  717. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  718. //支付成功
  719. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  720. }else{
  721. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  722. }
  723. }];
  724. // 授权跳转支付宝钱包进行支付,处理支付结果
  725. [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
  726. NSLog(@"result = %@",resultDic);
  727. // 解析 auth code
  728. NSString *result = resultDic[@"result"];
  729. NSString *authCode = nil;
  730. if (result.length>0) {
  731. NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  732. for (NSString *subResult in resultArr) {
  733. if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  734. authCode = [subResult substringFromIndex:10];
  735. break;
  736. }
  737. }
  738. }
  739. NSLog(@"授权结果 authCode = %@", authCode?:@"");
  740. }];
  741. }
  742. //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  743. // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  744. // return [WXApi handleOpenURL:url delegate:self];
  745. // }
  746. return YES;
  747. }
  748. #pragma mark - 广告展示
  749. #pragma mark 检查新旧
  750. - (void)onCheckVersion {
  751. if (![Util connectedToNetWork]){return;}
  752. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  753. NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  754. NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1225178346";
  755. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  756. [request setURL:[NSURL URLWithString:URL]];
  757. [request setHTTPMethod:@"POST"];
  758. NSOperationQueue *queue=[NSOperationQueue mainQueue];
  759. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  760. //这个导致部分手机网络不好时候出现闪退情况
  761. if (!data) {
  762. return;
  763. }
  764. //如果data等于nil的时候 再去解析 会发生崩溃
  765. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  766. if (!dic) {
  767. return;
  768. }
  769. NSArray *infoArray = [dic objectForKey:@"results"];
  770. if ([infoArray count]) {
  771. NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
  772. NSString *lastVersion = [releaseInfo objectForKey:@"version"];
  773. NSArray *last = [lastVersion componentsSeparatedByString:@"."];
  774. NSArray *current = [currentVersion componentsSeparatedByString:@"."];
  775. NSComparisonResult result = [last[0] compare:current[0]];
  776. if (result == NSOrderedDescending) {
  777. [self updateVersion];
  778. }else if(result == NSOrderedSame){
  779. result = [last[1] compare:current[1]];
  780. if (result == NSOrderedDescending) {
  781. [self updateVersion];
  782. }else if(result == NSOrderedSame){
  783. result = [last[2] compare:current[2]];
  784. if (result == NSOrderedDescending) {
  785. [self updateVersion];
  786. }
  787. }
  788. }
  789. }
  790. }];
  791. }
  792. - (void)getAppAnnouncement {
  793. if (![Util connectedToNetWork]) {
  794. showMsgUnconnect();
  795. return;
  796. }
  797. NSMutableArray *aArray=[NSMutableArray array];
  798. NSString* method = @"getAppAnnouncement";
  799. [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
  800. if (!root) {
  801. ShowMsgFailed();
  802. return ;
  803. }
  804. if ([root[@"code"] isEqualToString:@"0"]) {
  805. NSMutableString *content = [NSMutableString string];
  806. NSArray *strArr = root[@"data"][@"announcement"];
  807. NSMutableArray *idArr = [NSMutableArray array];
  808. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:kScreenWidth - 32];
  809. alert.customViewColor = defGreen;
  810. alert.viewText.textAlignment = NSTextAlignmentLeft;
  811. UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 64, kScreenHeight * 0.5)];
  812. view.font = [UIFont systemFontOfSize:15];
  813. [alert addButton:@"不再显示" actionBlock:^(void) {
  814. [[NSUserDefaults standardUserDefaults] setValue:@"doNotShowNotice" forKey:@"isShowNotice"];
  815. NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.announcementIDArr];
  816. [arr addObjectsFromArray:idArr];
  817. RQ_SHARE_FUNCTION.announcementIDArr = arr.copy;
  818. }];
  819. [[strArr.rac_sequence.signal filter:^BOOL(NSDictionary *dic) {
  820. return ![RQ_SHARE_FUNCTION.announcementIDArr containsObject:dic[@"ID"]];
  821. }] subscribeNext:^(NSDictionary *dic) {
  822. [idArr addObject:dic[@"ID"]];
  823. if (idArr.count > 1) {
  824. if (idArr.count == 2) {
  825. [content insertString:@"1." atIndex:0];
  826. [content appendFormat:@"%d.%@\n\n",(int)[idArr indexOfObject:dic[@"ID"]] + 1,dic[@"VALUE"]];
  827. }else {
  828. [content appendFormat:@"%d.%@\n\n",(int)[idArr indexOfObject:dic[@"ID"]] + 1,dic[@"VALUE"]];
  829. }
  830. }else {
  831. [content appendFormat:@"%@\n\n",dic[@"VALUE"]];
  832. }
  833. [[NSUserDefaults standardUserDefaults] setValue:@"ShowNotice" forKey:@"isShowNotice"];
  834. } completed:^{
  835. dispatch_main_async_safe(^{
  836. if (content.length == 0) {
  837. return;
  838. }
  839. view.text = content.mutableCopy;
  840. CGFloat textHeight = [view.text heightForWid:view.width Font:15];
  841. view.height = (textHeight > kScreenHeight/2)? kScreenHeight/2 : textHeight;
  842. [alert addCustomView:view];
  843. if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isKindOfClass:[NSString class]] && [[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isEqualToString:@"doNotShowNotice"]) {
  844. return;
  845. }else {
  846. [alert showInfo:@"公告" subTitle:@"" closeButtonTitle:@"确定" duration:0.0f];
  847. }
  848. })
  849. }];
  850. } else {
  851. ShowMsg(root[@"msg"]);
  852. return ;
  853. }
  854. }];
  855. }
  856. - (void)getAppAnnouncementOne {
  857. // NSDictionary *dic = @{};
  858. // dic = @{
  859. // @"TIME":@"5",@"ID":@"46",@"VALUE":@"告学员学车书",@"URL":@"http://lnxzzfile.oss-cn-beijing.aliyuncs.com//tms/student/contract/202111/appGG20220121001.pdf"
  860. // };
  861. // if (dic) {
  862. // self.announcementId = dic[@"ID"];
  863. // NSString *key1 = [NSString stringWithFormat:@"getAppAnnouncementShowOne%@",self.announcementId];
  864. // NSString *key2 = [NSString stringWithFormat:@"getAppAnnouncementShowTwo%@",self.announcementId];
  865. // if ([[RQPreferenceSettingHelper objectForKey:key1] boolValue] && [[RQPreferenceSettingHelper objectForKey:key2] boolValue]) {
  866. //
  867. // } else {
  868. // RQWebViewViewController *vc = [[RQWebViewViewController alloc] init];
  869. // vc.webType = WebTypeStuLearnBook;
  870. // vc.titleStr = dic[@"VALUE"];
  871. // vc.url = dic[@"URL"];
  872. // vc.countStr = dic[@"TIME"];
  873. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  874. // [RQ_SHARE_FUNCTION.topViewController rq_pushViewController:vc];
  875. // }
  876. // }
  877. // return;
  878. if (![Util connectedToNetWork]) {
  879. showMsgUnconnect();
  880. return;
  881. }
  882. NSMutableArray *aArray=[NSMutableArray array];
  883. NSString* method = @"getAppAnnouncement2";
  884. [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
  885. if (!root) {
  886. ShowMsgFailed();
  887. return ;
  888. }
  889. if ([root[@"code"] isEqualToString:@"0"]) {
  890. NSArray *announcementArr = root[@"data"][@"announcement"];
  891. if (announcementArr && announcementArr.count > 0) {
  892. NSDictionary *dic = announcementArr.firstObject;
  893. if (dic) {
  894. self.announcementId = dic[@"ID"];
  895. NSString *key1 = [NSString stringWithFormat:@"getAppAnnouncementShowOne%@",self.announcementId];
  896. NSString *key2 = [NSString stringWithFormat:@"getAppAnnouncementShowTwo%@",self.announcementId];
  897. if ([[RQPreferenceSettingHelper objectForKey:key1] boolValue] && [[RQPreferenceSettingHelper objectForKey:key2] boolValue]) {
  898. } else {
  899. RQWebViewViewController *vc = [[RQWebViewViewController alloc] init];
  900. vc.webType = WebTypeStuLearnBook;
  901. vc.titleStr = dic[@"VALUE"];
  902. vc.url = dic[@"URL"];
  903. vc.countStr = dic[@"TIME"];
  904. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  905. [RQ_SHARE_FUNCTION.topViewController rq_pushViewController:vc];
  906. }
  907. }
  908. }
  909. } else {
  910. ShowMsg(root[@"msg"]);
  911. return ;
  912. }
  913. }];
  914. }
  915. /// http://127.0.0.1:8083/lnwebservice_mysql/edu/getAppCompetence?ts=1645718529359&sign=ec124266ee1db3cec69d7fc4dc98a740&user=xzz&imsi=460064990040819
  916. - (void)getAppCompetence {
  917. if (![Util connectedToNetWork]) {
  918. showMsgUnconnect();
  919. return;
  920. }
  921. NSMutableArray *aArray=[NSMutableArray array];
  922. NSString* method = @"getAppCompetence";
  923. [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
  924. if (!root) {
  925. ShowMsgFailed();
  926. return ;
  927. }
  928. // {"body":"","code":"0","data":{"exerciseState":"0","exerciseMsg":"题库升级中..."},"msg":"成功","result":""}
  929. // exerciseState 0不开放,1开放
  930. if ([root[@"code"] isEqualToString:@"0"]) {
  931. NSDictionary *dic = root[@"data"];
  932. if (dic) {
  933. [RQPreferenceSettingHelper setObject:dic[@"exerciseState"] forKey:@"exerciseState"];
  934. [RQPreferenceSettingHelper setObject:dic[@"exerciseMsg"] forKey:@"exerciseMsg"];
  935. #if DEBUG
  936. [RQPreferenceSettingHelper setObject:@"1" forKey:@"exerciseState"];
  937. #endif
  938. }
  939. } else {
  940. ShowMsg(root[@"msg"]);
  941. return ;
  942. }
  943. }];
  944. }
  945. - (void)updateVersion {
  946. [RQ_Question_Module rq_showAppUpdateView];
  947. // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新提示" message:@"有新的版本发布,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
  948. // alert.tag = 10000;
  949. // [alert show];
  950. }
  951. #pragma mark 欢迎页面
  952. - (void)makeLaunchView {
  953. NSArray* images = @[@"welcom_page_1.jpg",@"welcom_page_2.jpg",@"welcom_page_3.jpg"
  954. ];//@"welcom_page_4.jpg"
  955. scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height)];
  956. scroll.bounces = NO;
  957. /**跳到最后页的下一页,也会欢迎结束
  958. */
  959. [scroll setContentSize:CGSizeMake(kSize.width* images.count+10, 0)];
  960. [scroll setBackgroundColor:[UIColor whiteColor]];
  961. [scroll setShowsHorizontalScrollIndicator:NO];
  962. [scroll setDelegate:self];
  963. scroll.pagingEnabled = YES;
  964. UIViewController *vc = [UIViewController new];
  965. [vc.view addSubview:scroll];
  966. // slide_right 图片
  967. [self.window setRootViewController:vc];
  968. pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, kSize.height-50, kSize.width, 20)];
  969. pageControl.userInteractionEnabled = NO;
  970. // pageControl.pageIndicatorTintColor = [UIColor blackColor];
  971. // pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
  972. pageControl.numberOfPages = scroll.contentSize.width/scroll.frame.size.width;
  973. [vc.view addSubview:pageControl];
  974. UIImageView *iv;
  975. for (int i =0; i<images.count; i++) {
  976. iv = [[UIImageView alloc] initWithFrame:kFrame];
  977. iv.x = kSize.width*i;
  978. [scroll addSubview:iv];
  979. [iv setImage:[UIImage imageNamed:images[i]]];
  980. if (i==images.count-1) {
  981. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  982. btn.frame = CGRectMake(kSize.width/2-45, kSize.height-90, 100, 40);
  983. btn.layer.masksToBounds = YES;
  984. btn.layer.cornerRadius = 8;
  985. btn.layer.borderWidth = 1;
  986. btn.layer.borderColor = [UIColor whiteColor].CGColor;
  987. [btn setTitle:@"开始使用" forState:UIControlStateNormal];
  988. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  989. btn.backgroundColor = [UIColor clearColor];
  990. [btn addTarget:self action:@selector(gotoChooseLib) forControlEvents:UIControlEventTouchUpInside];
  991. [iv addSubview:btn];
  992. iv.userInteractionEnabled = YES;
  993. }
  994. // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width*i, kSize.height*0.9, kSize.width, 35)];
  995. // [label setText:@"下一步 》" Font:32 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  996. // [scroll addSubview:label];
  997. //
  998. // UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width*i, kSize.height*0.9-7, kSize.width, 50)];
  999. // if (i==images.count-1) {
  1000. // btn.tag = 100;
  1001. // }
  1002. // [scroll addSubview:btn];
  1003. // [btn addTarget:self action:@selector(nextClick:) forControlEvents:UIControlEventTouchUpInside];
  1004. }
  1005. }
  1006. -(void)nextClick:(UIButton *)btn{
  1007. if (btn.tag == 100) {
  1008. [self gotoChooseLib];
  1009. return;
  1010. }
  1011. CGPoint off = scroll.contentOffset;
  1012. [scroll setContentOffset:CGPointMake(off.x+kSize.width, off.y) animated:YES];
  1013. }
  1014. /**欢迎结束后,先选择题库。
  1015. */
  1016. -(void)gotoChooseLib
  1017. {
  1018. if (defUser.isZhiGeZheng) {//@property(nonatomic,copy) NSString *isZhiGeZheng;
  1019. [self gotoLoad];
  1020. return;
  1021. }
  1022. ChooseExLibVC* vc = [ChooseExLibVC new];
  1023. [vc setIsWelcome:YES];
  1024. MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:vc];
  1025. [myDelegate.window setRootViewController:nav];
  1026. }
  1027. -(void)gotoMain
  1028. {
  1029. [self gotoLoad];
  1030. UIButton* btn = [[UIButton alloc] initWithFrame:kFrame];
  1031. [self.window addSubview:btn];
  1032. [btn setImage:[UIImage imageNamed:@"welGuide2.png"] forState:UIControlStateNormal];
  1033. UIImageView* iv;
  1034. iv = [[UIImageView alloc] initWithFrame:CGRectMake(3, 11, 70, 70)];
  1035. [iv setImage:[UIImage imageNamed:@"welGuide1.png"]];
  1036. [btn addSubview:iv];
  1037. [btn addTarget:self action:@selector(removeBtn:) forControlEvents:UIControlEventTouchUpInside];
  1038. }
  1039. -(void)removeBtn:(UIView*)btn
  1040. {
  1041. [btn removeFromSuperview];
  1042. }
  1043. //正常加载
  1044. -(void)gotoLoad
  1045. {
  1046. // YRSideViewController* sideVC = [[YRSideViewController alloc] init];
  1047. // TabBarController * tabbarVC = [[TabBarController alloc] init];
  1048. // tabbarVC.sideVC = sideVC;
  1049. // sideVC.rootViewController = tabbarVC;
  1050. // //是否开启手势滑动出菜单
  1051. // [sideVC setNeedSwipeShowMenu:NO];
  1052. //
  1053. // self.window.rootViewController = sideVC;
  1054. [self.services resetRootViewModel:[self rq_createInitialViewModel]];
  1055. }
  1056. #pragma mark - scorllview代理
  1057. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  1058. {
  1059. CGPoint off = scrollView.contentOffset;
  1060. if (off.x > kSize.width * 2) {
  1061. [self gotoChooseLib];
  1062. }
  1063. }
  1064. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  1065. pageControl.currentPage = scrollView.contentOffset.x/scrollView.frame.size.width;
  1066. }
  1067. - (void)test {
  1068. if (![Util connectedToNetWork]) {
  1069. showMsgUnconnect();
  1070. return;
  1071. }
  1072. NSMutableArray *arr=[NSMutableArray array];
  1073. NSString* method = @"doGetStudentActiveKhStatus";
  1074. [arr addPro:@"stuIdCard" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? defUser.sfzmhm : @"362324199302156513"];
  1075. [arr addPro:@"stuOutId" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? [NSString stringWithFormat:@"%@",defUser.userDict[@"outId"]] : @"2101000519225"];
  1076. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  1077. if (!root) {
  1078. ShowMsgFailed();
  1079. return ;
  1080. }
  1081. if ([root[@"code"] isEqualToString:@"0"]) {
  1082. ShowMsg(root[@"body"]);
  1083. return;
  1084. } else {
  1085. ShowMsg(root[@"body"]);
  1086. return;
  1087. }
  1088. }];
  1089. }
  1090. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  1091. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  1092. // 可以这么写
  1093. if (self.allowOrentitaionRotation) {
  1094. return UIInterfaceOrientationMaskAllButUpsideDown;
  1095. }
  1096. return UIInterfaceOrientationMaskPortrait;
  1097. }
  1098. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  1099. // 通用链接
  1100. if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  1101. NSURL *url = userActivity.webpageURL;
  1102. NSLog(@"通用链接 :%@", url);
  1103. if ([[url absoluteString] containsString:@"wx606fa102dbc4b8ab"]) {
  1104. return [WXApi handleOpenUniversalLink:userActivity
  1105. delegate:self];
  1106. } else if ([[url absoluteString] containsString:@"https://app.jppt.com.cn/JSJPStudent/"]) {
  1107. return YES;
  1108. }
  1109. return NO;
  1110. }
  1111. return NO;
  1112. }
  1113. #pragma mark - 在初始化UI之前配置
  1114. - (void)rq_configureApplication:(UIApplication *)application initialParamsBeforeInitUI:(NSDictionary *)launchOptions {
  1115. // 配置键盘
  1116. // [self rq_configureKeyboardManager];
  1117. // 配置文件夹
  1118. // [self rq_configureApplicationDirectory];
  1119. // 配置FMDB
  1120. // [self rq_configureFMDB];
  1121. // 配置流音乐播放
  1122. // [DOUAudioStreamer setOptions:[DOUAudioStreamer options] | DOUAudioStreamerRequireSHA256];
  1123. // 配置微信
  1124. // [self rq_configureWechat];
  1125. [self rq_configureNetState];
  1126. [self getConfigKey];
  1127. [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media"] subscribeNext:^(id _Nullable x) {
  1128. RQ_COMMON_MANAGER.is_Online_Media = [x boolValue];
  1129. }];
  1130. [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media_Image"] subscribeNext:^(id _Nullable x) {
  1131. RQ_COMMON_MANAGER.is_Online_Media_Image = [x boolValue];
  1132. }];
  1133. [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media_Video"] subscribeNext:^(id _Nullable x) {
  1134. RQ_COMMON_MANAGER.is_Online_Media_Video = [x boolValue];
  1135. }];
  1136. [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_HY_FACE_NUM"] subscribeNext:^(id _Nullable x) {
  1137. RQ_COMMON_MANAGER.LN_HY_FACE_NUM = [x integerValue];
  1138. }];
  1139. [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_NET_EDU_FACE_NUM"] subscribeNext:^(id _Nullable x) {
  1140. RQ_COMMON_MANAGER.LN_NET_EDU_FACE_NUM = [x integerValue];
  1141. }];
  1142. [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_SHEQU_OPEN"] subscribeNext:^(id _Nullable x) {
  1143. RQ_COMMON_MANAGER.LN_SHEQU_OPEN = [x boolValue];
  1144. }];
  1145. [[RQ_HTTP_Service getOldFaceHistoryListList] subscribeNext:^(NSArray *oldFaceHistoryListListArr) {
  1146. NSArray *arr = [[oldFaceHistoryListListArr.rac_sequence.signal filter:^BOOL(RQDictInfoModel *dictInfoModel) {
  1147. return [dictInfoModel.status isEqualToString:@"0"];
  1148. }].toArray.rac_sequence.signal map:^id _Nullable(RQDictInfoModel *dictInfoModel) {
  1149. return dictInfoModel.dictValue;
  1150. }].toArray;
  1151. RQ_COMMON_MANAGER.oldFaceHistoryListListArr = RQObjectIsNil(arr)? @[] : arr;
  1152. }];
  1153. [[RQ_HTTP_Service getChapterList] subscribeNext:^(id _Nullable x) {
  1154. }];
  1155. /// 初始化百度人脸识别SDK
  1156. [self initDBFaceSDK];
  1157. /// 定位权限请求
  1158. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location) {
  1159. }];
  1160. if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) {
  1161. [self rq_AD];
  1162. if (RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN) {
  1163. [RQ_AD_MODULE loadAdWithAdType:GromoreAdTypeSplash customView:nil];
  1164. }
  1165. }
  1166. }
  1167. - (void)rq_configureNetState {
  1168. /// 开启网络监测
  1169. [[ZFReachabilityManager sharedManager] startMonitoring];
  1170. [[ZFReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(ZFReachabilityStatus status) {
  1171. }];
  1172. }
  1173. // 配置键盘管理器
  1174. - (void)rq_configureKeyboardManager {
  1175. IQKeyboardManager.sharedManager.enable = YES;
  1176. IQKeyboardManager.sharedManager.enableAutoToolbar = NO;
  1177. IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = YES;
  1178. }
  1179. // 配置文件夹
  1180. - (void)rq_configureApplicationDirectory {
  1181. /// 创建doc
  1182. [RQFileManager createDirectoryAtPath:RQWeChatDocDirPath()];
  1183. /// 创建cache
  1184. [RQFileManager createDirectoryAtPath:RQWeChatCacheDirPath()];
  1185. NSLog(@"RQWeChatDocDirPath is [ %@ ] \n RQWeChatCacheDirPath is [ %@ ]" , RQWeChatDocDirPath() , RQWeChatCacheDirPath());
  1186. }
  1187. /// 配置FMDB
  1188. - (void)rq_configureFMDB {
  1189. // FMDatabaseQueue *databaseQueue = [[FMDatabaseQueue alloc] init];
  1190. // [databaseQueue inDatabase:^(FMDatabase *db) {
  1191. // NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  1192. // if (![version isEqualToString:RQ_APP_VERSION]) {
  1193. // NSString *path = [[NSBundle mainBundle] pathForResource:@"question20210722" ofType:@"db"];
  1194. // NSString *sql = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  1195. // /// 执行文件
  1196. // if (![db executeStatements:sql]) {
  1197. // RQLogLastError(db);
  1198. // }
  1199. // }
  1200. // }];
  1201. NSFileManager *fileManager =[NSFileManager defaultManager];
  1202. NSError*error;
  1203. if ([fileManager fileExistsAtPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"question20210722.db"]]]== NO) {
  1204. NSString*resourcePath =[[NSBundle mainBundle] pathForResource:@"question20210722" ofType:@"db"];
  1205. [fileManager copyItemAtPath:resourcePath toPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"question20210722.db"]] error:&error];
  1206. }
  1207. if (RQ_USER_MANAGER.isLogin) {
  1208. [RQ_UPDATE_LOCALDATA_MANAGER updateLocalCollectionListWithComplete:nil];
  1209. [RQ_UPDATE_LOCALDATA_MANAGER updateLocalWrongListWithComplete:nil];
  1210. }
  1211. }
  1212. - (void)rq_configureWechat {
  1213. /// 向微信注册
  1214. [RQ_WECHAT_MANAGER initWechatManager];
  1215. }
  1216. #pragma mark - 在初始化UI之后配置
  1217. - (void)rq_configureApplication:(UIApplication *)application initialParamsAfterInitUI:(NSDictionary *)launchOptions {
  1218. /// 配置ActionSheet
  1219. [LCActionSheet rq_configureActionSheet];
  1220. /// 预先配置平台信息
  1221. // [SBUMengService configureUMengPreDefinePlatforms];
  1222. @weakify(self);
  1223. /// 监听切换根控制器的通知
  1224. [[RQNotificationCenter rac_addObserverForName:RQSwitchRootViewControllerNotification object:nil] subscribeNext:^(NSNotification * note) {
  1225. /// 这里切换根控制器
  1226. @strongify(self);
  1227. // 重置rootViewController
  1228. RQSwitchRootViewControllerFromType fromType = [note.userInfo[RQSwitchRootViewControllerUserInfoKey] integerValue];
  1229. NSLog(@"fromType is %zd" , fromType);
  1230. /// 切换根控制器
  1231. [self.services resetRootViewModel:[self rq_createInitialViewModel]];
  1232. /// 切换了根控制器,切记需要将指示器 移到window的最前面
  1233. #if defined(DEBUG)||defined(_DEBUG)
  1234. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  1235. #endif
  1236. }];
  1237. /// 配置H5
  1238. // [SBConfigureManager configure];
  1239. }
  1240. #pragma mark - 调试(DEBUG)模式下的工具条
  1241. - (void)rq_configDebugModelTools {
  1242. /// 显示FPS
  1243. [[JPFPSStatus sharedInstance] open];
  1244. /// 打开调试按钮
  1245. [RQDebugTouchView sharedInstance];
  1246. /// RQ Fixed: 切换了根控制器,切记需要将指示器 移到window的最前面
  1247. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  1248. }
  1249. #pragma mark - 创建根控制器
  1250. - (RQBaseViewModel *)rq_createInitialViewModel {
  1251. // The user has logged-in.
  1252. // NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  1253. /// 版本不一样就先走 新特性界面
  1254. // if (![version isEqualToString:RQ_APP_VERSION]){
  1255. // return [[RQNewFeatureViewModel alloc] initWithServices:self.services params:nil];
  1256. // }else{
  1257. /// 这里判断一下
  1258. // if ([SAMKeychain rawLogin] && self.services.client.currentUser) {
  1259. /// 有账号+有用户数据
  1260. /// 已经登录,跳转到主页
  1261. return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  1262. // }else if(self.services.client.currentUser){ /// 没账号+有用户数据
  1263. /// 跳转到账户登录页面
  1264. // return [[RQAccountLoginViewModel alloc] initWithServices:self.services params:nil];
  1265. // }else{
  1266. /// 第一次使用微信
  1267. // return [[RQBootLoginViewModel alloc] initWithServices:self.services params:nil];
  1268. // }
  1269. // }
  1270. }
  1271. - (void)getVideoTypeList {
  1272. [[RQ_HTTP_Service getTreeList] subscribeNext:^(NSArray <RQTreeListModel *> * dataArr) {
  1273. if (!RQObjectIsNil(dataArr)) {
  1274. RQ_COMMON_MANAGER.treeListArr = dataArr;
  1275. }
  1276. }];
  1277. // NSMutableArray *arr = [NSMutableArray array];
  1278. // [arr addPro:@"videoTypeId" Value:@"20"];
  1279. //
  1280. // NSString *method= @"/open-api/teachingVideo/info/getTeachingVideoByTypeId";
  1281. //
  1282. // [jiaPeiManager requestGetAnythingWithURL:method array:arr completion:^(NSDictionary *dict) {
  1283. //
  1284. // }];
  1285. }
  1286. #pragma mark - initDBFaceSDK
  1287. - (void)initDBFaceSDK {
  1288. [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"SoundMode"];
  1289. [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"LiveMode"];
  1290. [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"ByOrder"];
  1291. [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"checkAgreeBtn"];
  1292. NSString* licensePath = [NSString stringWithFormat:@"%@.%@", FACE_LICENSE_NAME, FACE_LICENSE_SUFFIX ];
  1293. [[FaceSDKManager sharedInstance] setLicenseID:FACE_LICENSE_ID andLocalLicenceFile:licensePath andRemoteAuthorize:false];
  1294. NSLog(@"canWork = %d",[[FaceSDKManager sharedInstance] canWork]);
  1295. NSLog(@"version = %@",[[FaceSDKManager sharedInstance] getVersion]);
  1296. [self initSDK];
  1297. [self initLivenesswithList];
  1298. }
  1299. - (void)initSDK {
  1300. if (![[FaceSDKManager sharedInstance] canWork]){
  1301. NSLog(@"授权失败,请检测ID 和 授权文件是否可用");
  1302. return;
  1303. }
  1304. // 初始化SDK配置参数,可使用默认配置
  1305. // 设置最小检测人脸阈值
  1306. [[FaceSDKManager sharedInstance] setMinFaceSize:200];
  1307. // 设置截取人脸图片高
  1308. [[FaceSDKManager sharedInstance] setCropFaceSizeWidth:480];
  1309. // 设置截取人脸图片宽
  1310. [[FaceSDKManager sharedInstance] setCropFaceSizeHeight:640];
  1311. // 设置人脸遮挡阀值
  1312. [[FaceSDKManager sharedInstance] setOccluThreshold:0.5];
  1313. // 设置亮度阀值
  1314. [[FaceSDKManager sharedInstance] setMinIllumThreshold:40];
  1315. [[FaceSDKManager sharedInstance] setMaxIllumThreshold:240];
  1316. // 设置图像模糊阀值
  1317. [[FaceSDKManager sharedInstance] setBlurThreshold:0.3];
  1318. // 设置头部姿态角度
  1319. [[FaceSDKManager sharedInstance] setEulurAngleThrPitch:10 yaw:10 roll:10];
  1320. // 设置人脸检测精度阀值
  1321. [[FaceSDKManager sharedInstance] setNotFaceThreshold:0.6];
  1322. // 设置抠图的缩放倍数
  1323. [[FaceSDKManager sharedInstance] setCropEnlargeRatio:2.5];
  1324. // 设置照片采集张数
  1325. [[FaceSDKManager sharedInstance] setMaxCropImageNum:3];
  1326. // 设置超时时间
  1327. [[FaceSDKManager sharedInstance] setConditionTimeout:15];
  1328. // 设置开启口罩检测,非动作活体检测可以采集戴口罩图片
  1329. [[FaceSDKManager sharedInstance] setIsCheckMouthMask:true];
  1330. // 设置开启口罩检测情况下,非动作活体检测口罩过滤阈值,默认0.8 不需要修改
  1331. [[FaceSDKManager sharedInstance] setMouthMaskThreshold:0.8f];
  1332. // 设置原始图缩放比例
  1333. [[FaceSDKManager sharedInstance] setImageWithScale:0.8f];
  1334. // 设置图片加密类型,type=0 基于base64 加密;type=1 基于百度安全算法加密
  1335. [[FaceSDKManager sharedInstance] setImageEncrypteType:0];
  1336. // 初始化SDK功能函数
  1337. [[FaceSDKManager sharedInstance] initCollect];
  1338. // 设置人脸过远框比例
  1339. [[FaceSDKManager sharedInstance] setMinRect:0.4];
  1340. /// 设置用户设置的配置参数
  1341. [BDFaceAdjustParamsTool setDefaultConfig];
  1342. }
  1343. - (void)initLivenesswithList {
  1344. // 默认活体检测打开,顺序执行
  1345. /*
  1346. 添加当前默认的动作,是否需要按照顺序,动作活体的数量(设置页面会根据这个numOfLiveness来判断选择了几个动作)
  1347. */
  1348. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveEye)];
  1349. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveMouth)];
  1350. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYawRight)];
  1351. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYawLeft)];
  1352. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLivePitchUp)];
  1353. [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLivePitchDown)];
  1354. // [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYaw)];
  1355. BDFaceLivingConfigModel.sharedInstance.isByOrder = NO;
  1356. BDFaceLivingConfigModel.sharedInstance.numOfLiveness = 3;
  1357. }
  1358. - (void) destorySDK {
  1359. // 销毁SDK功能函数
  1360. [[FaceSDKManager sharedInstance] uninitCollect];
  1361. }
  1362. - (void)getConfigKey {
  1363. [[RQ_HTTP_Service getYyxcSet] subscribeNext:^(NSArray *setArr) {
  1364. [setArr.rac_sequence.signal subscribeNext:^(RQDictInfoModel *dictInfoModel) {
  1365. if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_OPEN"]) {
  1366. RQ_COMMON_MANAGER.YYXC_AD_OPEN = [dictInfoModel.dictValue boolValue];
  1367. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_SPLASH_AD_OPEN"]) {
  1368. RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN = [dictInfoModel.dictValue boolValue];
  1369. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_NATIVE_AD_OPEN"]) {
  1370. RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN = [dictInfoModel.dictValue boolValue];
  1371. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_BANNER_AD_OPEN"]) {
  1372. RQ_COMMON_MANAGER.YYXC_BANNER_AD_OPEN = [dictInfoModel.dictValue boolValue];
  1373. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_SERVICE_OPEN"]) {
  1374. RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN = [dictInfoModel.dictValue boolValue];
  1375. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_TIME1"]) {
  1376. RQ_COMMON_MANAGER.YYXC_AD_TIME1 = dictInfoModel.dictValue;
  1377. } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_TIME2"]) {
  1378. RQ_COMMON_MANAGER.YYXC_AD_TIME2 = dictInfoModel.dictValue;
  1379. } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media"]) {
  1380. RQ_COMMON_MANAGER.is_Online_Media = dictInfoModel.dictValue.boolValue;
  1381. } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media_Image"]) {
  1382. RQ_COMMON_MANAGER.is_Online_Media_Image = dictInfoModel.dictValue.boolValue;
  1383. } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media_Video"]) {
  1384. RQ_COMMON_MANAGER.is_Online_Media_Video = dictInfoModel.dictValue.boolValue;
  1385. } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_HY_FACE_NUM"]) {
  1386. RQ_COMMON_MANAGER.LN_HY_FACE_NUM = dictInfoModel.dictValue.integerValue;
  1387. } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_NET_EDU_FACE_NUM"]) {
  1388. RQ_COMMON_MANAGER.LN_NET_EDU_FACE_NUM = dictInfoModel.dictValue.integerValue;
  1389. } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_SHEQU_OPEN"]) {
  1390. RQ_COMMON_MANAGER.LN_SHEQU_OPEN = dictInfoModel.dictValue.integerValue;
  1391. }
  1392. }];
  1393. }];
  1394. }
  1395. //- (void)setThirtyPartySdk {
  1396. // if ([self isFirstAppLoad]) {
  1397. // // 记录是否第一次启动
  1398. // [self writeAppLoad];
  1399. // // 获取idfa权限 建议启动就获取权限 不获取权限会影响收益
  1400. // if (@available(iOS 14.0, *)) {
  1401. // [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
  1402. //
  1403. // }];
  1404. // }
  1405. // // 用户同意隐私后 初始化
  1406. // [self rq_GDTSDK];
  1407. // }else {
  1408. // [self rq_GDTSDK];
  1409. // }
  1410. //}
  1411. - (void)writeAppLoad {
  1412. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  1413. [userDefault setObject:@"yes" forKey:@"isFirstLoad"];
  1414. [userDefault synchronize];
  1415. }
  1416. - (BOOL)isFirstAppLoad {
  1417. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  1418. if ([[userDefault objectForKey:@"isFirstLoad"] isEqualToString:@"yes"]) {
  1419. return NO;
  1420. }
  1421. return YES;
  1422. }
  1423. - (void)rq_AD {
  1424. #pragma mark 设定流量分组
  1425. // [self userSegmentSetting];
  1426. #pragma mark 隐私配置设置
  1427. [self privateSetting];
  1428. #pragma mark 初始化Gromore SDK
  1429. if (@available(iOS 14, *)) {
  1430. [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
  1431. [self initGromoreSDK];
  1432. }];
  1433. } else {
  1434. [self initGromoreSDK];
  1435. }
  1436. }
  1437. /// 初始化Gromore SDK
  1438. - (void)initGromoreSDK {
  1439. // Gromore SDK初始化方法
  1440. [ABUAdSDKManager setupSDKWithAppId:@"5377374" config:^ABUUserConfig *(ABUUserConfig *c) {
  1441. // 打开日志开关,线上环境请关闭
  1442. c.logEnable = YES;
  1443. c.testMode = YES;
  1444. // 设定自定义IDFA,根据实际情况设定
  1445. c.customIDFA = @"00000000-0000-0000-0000-000000000001";
  1446. return c;
  1447. }];
  1448. ABUSplashAd *splashAd = [[ABUSplashAd alloc] initWithAdUnitID:@""];
  1449. splashAd.rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
  1450. ABUFullscreenVideoAd *fullscreenVideoAd = [[ABUFullscreenVideoAd alloc] initWithAdUnitID:@""];
  1451. fullscreenVideoAd.mutedIfCan = YES;//静音
  1452. // 新接口,用于传入首次预缓存的广告对象
  1453. // [ABUAdSDKManager preloadAdsWithInfos:@[splashAd, fullscreenVideoAd] andInterval:2 andConcurrent:2];
  1454. }
  1455. /// 流量分组设定
  1456. - (void)userSegmentSetting {
  1457. ABUUserInfoForSegment *segment = [[ABUUserInfoForSegment alloc] init];
  1458. segment.user_id = @"Please enter your user's Id";
  1459. segment.user_value_group = @"group1";
  1460. segment.age = 19;
  1461. segment.gender = ABUUserInfo_Gender_Male;
  1462. segment.channel = @"Apple";
  1463. segment.sub_channel = @"Apple store";
  1464. segment.customized_id = @{@(1):@"345",// key非string,不合规
  1465. @"key2":@"good",// 合规,上报
  1466. @"key3":@(1),// value非string,不合规
  1467. @"key4":@"123aA-_",// 合规,上报
  1468. @"key5":@"123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_1",// 长度超100,不合规
  1469. @"key6":@"123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_",// 合规,上报
  1470. @"key7":@"123aA-_*",// value包含特殊字符,不合规
  1471. };
  1472. [ABUAdSDKManager setUserInfoForSegment:segment];
  1473. }
  1474. /// 隐私设置
  1475. - (void)privateSetting {
  1476. [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyForbiddenIDFA andValue:@(0)];
  1477. [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyForbiddenCAID andValue:@(0)];
  1478. [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLimitPersonalAds andValue:@(0)];
  1479. [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLongitude andValue:@(115.7)];
  1480. [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLatitude andValue:@(39.4)];
  1481. }
  1482. @end