// // AppDelegate.m // jiaPei // // Created by apple on 15/11/2. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "AppDelegate.h" #import "ChooseExLibVC.h" #import "ADView.h" #import "MyMsgVC.h" #import "NewsDetVC.h" #import "TopicVC.h" #import "AllCoachPlanVC.h" #import "Tools.h" #import "MyUINavigationController.h" #pragma mark MOB //分享 //#import //#import //短信验证 //#import #import "WXApiManager.h" //腾讯开放平台(对应QQ和QQ空间)SDK头文件 //#import //#import //微信SDK头文件 #import #import //微信支付器 #import "payRequsestHandler.h" //支付 #import //bugly腾讯bug统计 #import #import /// 百度人脸识别 #import #import "FaceParameterConfig.h" #import "BDFaceAdjustParamsTool.h" #import "BDFaceLivingConfigModel.h" # if __has_include() #import #else #import #endif #import //#import @interface AppDelegate () { UIScrollView *scroll; NSString *pushType; NSString *pushID; UIPageControl *pageControl; } @property (assign , nonatomic) BOOL isShow; /// APP管理的导航栏的堆栈 @property (nonatomic, readwrite, strong) RQNavigationControllerStack *navigationControllerStack; /// APP的服务层 @property (nonatomic, readwrite, strong) RQViewModelServicesImpl *services; @property (nonatomic, assign, readwrite) AFNetworkReachabilityStatus networkReachabilityStatus; @end @implementation AppDelegate #pragma mark- 获取appDelegate + (AppDelegate *)sharedDelegate { return (AppDelegate *)[[UIApplication sharedApplication] delegate]; } //程序开始 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ /// 初始化UI之前配置 [self rq_configureApplication:application initialParamsBeforeInitUI:launchOptions]; // Config Service self.services = [[RQViewModelServicesImpl alloc] init]; // Config Nav Stack self.navigationControllerStack = [[RQNavigationControllerStack alloc] initWithServices:self.services]; // Configure Window self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; // 重置rootViewController [self.services resetRootViewModel:[self rq_createInitialViewModel]]; // 让窗口可见 [self.window makeKeyAndVisible]; [RQ_CACHE_MANAGER removeAllCache]; // 初始化UI后配置 [self rq_configureApplication:application initialParamsAfterInitUI:launchOptions]; #if defined(DEBUG)||defined(_DEBUG) /// 调试模式 [self rq_configDebugModelTools]; #endif // Save the application version info. must write last [[NSUserDefaults standardUserDefaults] setValue:RQ_APP_VERSION forKey:RQApplicationVersionKey]; [[NSUserDefaults standardUserDefaults] synchronize]; // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil]; //获取沙盒 //NSLog(@"沙盒-->%@",NSHomeDirectory()); _isShow = NO; [self registerThirdSDK]; //同步本地数据 [UserInfo shareInfo]; if (defUser.userDict) { _isLogin = YES; } //默认车型C1 if (!defUser.car_type) { defUser.car_type = @"C1"; RQ_YDTQuestion_Module.carType = RQHomePageCarType_Car; } //默认科目一 if (!myDelegate.subject) { myDelegate.subject = @"1"; RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne; } #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_10_0 //这里即使不判断系统版本,后面也做了避免消息重复处理。didReceiveNotificationResponse 统一处理 //远程通知 if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) { //关于这个方法远程和进程不一样 一个是userinfo字典。一个是本地通知 NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; //这里不用判断重复消息 NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"]; [userDefaults synchronize]; NSString *jsonStr = userInfo[@"payload"]; if ([jsonStr length] != 0) { NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding]; if (data) { NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]]; pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]]; //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关 if ([pushType integerValue]>=1 && [pushType integerValue]<=6) { [self gotoPush]; }else{ //其它信息 [self gotoLoad]; [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]]; } return YES; } } } #endif if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { //异步获取新的广告 [jiaPeiManager requestADImage]; } //判断跳转页面 这样每次更新版本 都会有导航页 NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *vesionNow = [infoDic objectForKey:@"CFBundleShortVersionString"]; if (![defUser.isWelcomed isEqualToString:vesionNow]) { defUser.isWelcomed = vesionNow; // myDelegate.isSyn = YES; //要在这里清空数据库 如果版本需要更新数据库 可以在这里更新 不过 如果更新了 本地库里边保存的信息会不见 主要是miaxis.db这个库 里边有科目练习题 //如果更新了新的数据库 第一次运行的时候要加上下面这句代码 移除旧的数据库 重新copy到document文件目录下 //[DB_Que_Helper removeDB]; [self makeLaunchView]; }else{ if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) { if (RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN) { } else { //在这里搞个 广告页面 加载广告 [ADView showADView]; } } } [self gotoLoad]; // 加载开屏广告 // [self loadSplashAd]; @try { [self onCheckVersion]; } @catch (NSException *exception) { } @finally { } } /**微信支付 1、导入微信支付SDK,注册微信支付 2、设置微信appid为URL schemes 3、发起支付,调用微信支付 4、处理支付结果 */ [WXApi registerApp:WEIXIN_APPID universalLink:@"https://eqext.share2dlink.com/"]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { /// 显示公告 [self getAppAnnouncement]; /// 显示硬性公告 [self getAppAnnouncementOne]; /// [self getAppCompetence]; } SDImageWebPCoder*webPCoder = [SDImageWebPCoder sharedCoder]; [[SDImageCodersManager sharedManager] addCoder:webPCoder]; // [self test]; // [self getVideoTypeList]; // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil]; /// 更新题库 [RQ_Question_Module rq_updateQuestion]; // [ABUVisualDebug startVisualDebug]; [RQ_APPDELEGATE.window bringSubviewToFront:RQ_TIMING_VIEW]; return YES; } //程序复原 - (void)applicationDidBecomeActive:(UIApplication *)application{ //删除程序小红点 [GeTuiSdk resetBadge]; //重置角标计数 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; //APP 清空角标 if (myDelegate.timer) { [myDelegate.timer setFireDate:[NSDate distantPast]]; } myDelegate.isBackgroundTask = NO; [RQ_TIMING_VIEW continueTiming]; } //程序挂起 - (void)applicationWillResignActive:(UIApplication *)application { } //程序进入后台 - (void)applicationDidEnterBackground:(UIApplication *)application { if (myDelegate.timer) {//理论 [myDelegate.timer setFireDate:[NSDate distantFuture]]; } myDelegate.isBackgroundTask = YES; [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(){}]; [RQ_TIMING_VIEW pauseTiming]; } //程序到前台 - (void)applicationWillEnterForeground:(UIApplication *)application { //[ADView showADView]; } //程序意外退出 - (void)applicationWillTerminate:(UIApplication *)application { //NSLog(@"程序退出"); 程序退出要将登录状态置为未登录状态 } /// 应用处于后台,所有下载任务完成调用 - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.backgroundSessionCompletionHandler = completionHandler; } #pragma mark 第三方sdk注册 -(void)registerThirdSDK{ //异常统计 #ifdef DEBUG //do sth1. [Bugly startWithAppId:BUGLY_APP_ID]; #else [Bugly startWithAppId:BUGLY_APP_ID]; #endif //个推 // 通过个推平台分配的appId、 appKey 、appSecret 启动SDK,注:该方法需要在主线程中调用 [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self launchingOptions:nil]; // 注册 APNs [self registerRemoteNotification]; //初始化地图 _mapManager = [[BMKMapManager alloc]init]; // 如果要关注网络及授权验证事件,请设定 generalDelegate参数 BOOL ret = [_mapManager start:BAIDU_APPKEY generalDelegate:self]; if (!ret) { //NSLog(@"%d",ret); NSLog(@"manager start failed!"); } //注册分享 // [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) { // //QQ // [platformsRegister setupQQWithAppId:QQ_APPID appkey:QQ_APPKEY enableUniversalLink:NO universalLink:nil]; // // //更新到4.3.3或者以上版本,微信初始化需要使用以下初始化 // [platformsRegister setupWeChatWithAppId:WEIXIN_APPID appSecret:WEIXIN_APPSECRET universalLink:@"https://eqext.share2dlink.com/"]; // }]; //注册短信验证 // [SMSSDK registerApp:SHARE_DX_APPKEY // withSecret:SHARE_DX_SCRECT]; //注册分享 // [ShareSDK registerApp:SHARE_FX_APPKEY // // activePlatforms:@[@(SSDKPlatformTypeCopy), // @(SSDKPlatformTypeWechat), // @(SSDKPlatformTypeQQ)] // onImport:^(SSDKPlatformType platformType) // { // switch (platformType) // { // case SSDKPlatformTypeWechat: // [ShareSDKConnector connectWeChat:[WXApi class]]; // break; // case SSDKPlatformTypeQQ: // [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]]; // break; // default: // break; // } // } // onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) // { // switch (platformType) // { // case SSDKPlatformTypeWechat: // [appInfo SSDKSetupWeChatByAppId:WEIXIN_APPID // appSecret:WEIXIN_APPSECRET]; // break; // case SSDKPlatformTypeQQ: // [appInfo SSDKSetupQQByAppId:QQ_APPID // appKey:QQ_APPKEY // authType:SSDKAuthTypeBoth]; // break; // default: // break; // } // }]; } #pragma mark 推送注册 /** 注册 APNs */ - (void)registerRemoteNotification { /* 警告:Xcode8及以上版本 需要手动开启"TARGETS -> Capabilities -> Push Notifications" */ /* 警告:该方法需要开发者自定义,以下代码根据 APP 支持的 iOS 系统不同,代码可以对应修改。 以下为演示代码,注意根据实际需要修改,注意测试支持的 iOS 系统都能获取到 DeviceToken */ if (iOS10) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) { if (!error) { NSLog(@"request authorization succeeded!(iOS >= 10.0)"); } }]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [[UIApplication sharedApplication] registerForRemoteNotifications]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge); [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type]; #pragma clang diagnostic pop } } /** 远程通知注册成功委托 */ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; NSLog(@"\n>>>[DeviceToken Success]:%@\n\n", token); // 向个推服务器注册deviceToken [GeTuiSdk registerDeviceToken:token]; } /** 远程通知注册失败委托 */ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"FailToRegisterForRemoteNotificationsWithError:%@",error); } //iOS7.0 以后支持 APP 后台刷新数据,会回调 performFetchWithCompletionHandler 接口。为保证个推SDK的数据刷新,需在该回调接口中调用[GeTuiSdk resume]方法帮助个推 SDK 刷新数据。 - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { /// Background Fetch 恢复SDK 运行 [GeTuiSdk resume]; completionHandler(UIBackgroundFetchResultNewData); } #pragma mark - iOS < 10 //处理 APNs 通知点击事件,统计有效用户点击数- (App运行在后台/App运行在前台) and apns静默推送消息处理 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"didReceiveRemoteNotification and iOS<10"); // 将收到的APNs信息传给个推统计 [GeTuiSdk handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); [self remoteNotificationDealWithDic:userInfo]; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { //接收到本地通知方法 if (notification) { if (!_isShow) { [self showTheoryWindow]; } } } - (void)showTheoryWindow { _isShow = YES; [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"即将超过验证时间,请提前扫码验证" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:@[] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) { _isShow = NO; }]; } #pragma mark iOS > 10 //对于iOS 10 及以后版本,为处理 APNs 通知点击,统计有效用户点击数,需先添加 UNUserNotificationCenterDelegate #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // iOS 10: App在前台获取到通知 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { NSLog(@"willPresentNotification and iOS>10前台获取到通知:%@", notification.request.content.userInfo); if ([notification.request.identifier isEqualToString:@"Theory"]) { if (!_isShow) { [self showTheoryWindow]; } } // 根据APP需要,判断是否要提示用户Badge、Sound、Alert completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert); } // iOS 10: 点击通知进入App时触发,在该方法内统计有效用户点击数 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { NSLog(@"didReceiveNotification and iOS>10后台获取到通知:%@", response.notification.request.content.userInfo); // [ GTSdk ]:将收到的APNs信息传给个推统计 [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo]; completionHandler(); if ([response.notification.request.identifier isEqualToString:@"Theory"]) { if (!_isShow) { [self showTheoryWindow]; } }else { //此处表述程序由远程通知启动打开(不是点击桌面icon) NSDictionary* userInfo = response.notification.request.content.userInfo; [self remoteNotificationDealWithDic:userInfo]; } } #endif #pragma mark - 个推相关方法 /** SDK启动成功返回cid 在这里将cid给自己的服务器 */ - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId { //个推SDK已注册,返回clientId NSLog(@"\n>>>[GeTuiSdk RegisterClient]:%@\n\n", clientId); //NSLog(@"获取推送token执行"); myDelegate.token = clientId; NSString *tokenPass = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"apnsToken.plist"]; if (![myDelegate.token writeToFile:tokenPass atomically:YES encoding:NSUTF8StringEncoding error:nil]) { NSLog(@"保存失败"); } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { upLoadToken(); } //注册成功,将deviceToken保存到应用服务器数据库中 // [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""] // stringByReplacingOccurrencesOfString:@">" withString:@""] // stringByReplacingOccurrencesOfString:@" " withString:@""] } /** SDK遇到错误回调 */ - (void)GeTuiSdkDidOccurError:(NSError *)error { //个推错误报告,集成步骤发生的任何错误都在这里通知,如果集成后,无法正常收到消息,查看这里的通知。 // NSLog(@"\n>>>[GexinSdk error]:%@\n\n", [error localizedDescription]); } /** SDK收到透传消息回调 *//*(个推-客户端)*/ - (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId { //收到个推消息 if (payloadData) { NSString * payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding]; NSLog(@"GeTuiSdkDidReceivepayloadMsg:%@",payloadMsg); //判断是否被处理过[即发送离线消息的时候,会走apns+个推sdk(有效期内)] //ps:这里处理之后不做存档操作,保证点击通知栏的时候可以”再处理一次“ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSString *oldmsgId = [userDefaults objectForKey:@"remoteNotifymsgId"]; if ([oldmsgId isEqualToString:msgId]) { return; } NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:payloadData options:NSJSONReadingMutableContainers error:nil]; if (payloadDic.count == 0) { return; } pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]]; pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]]; if ([pushType integerValue]>=1 && [pushType integerValue]<=5) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:payloadDic[@"title"] message:payloadDic[@"body"] preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [self gotoPush]; }]]; [self.window.rootViewController presentViewController:alertFind animated:true completion:nil]; }else{ //其它信息 [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]]; } } } #pragma mark 远程通知的数据处理 -(void)remoteNotificationDealWithDic:(NSDictionary *)userInfo{ /* { "_ge_" = 1; "_gmid_" = "OSL-0818_bJ6zVRy8cC6JsflZOYPXO9:965f14a1051748c4a48f9db2437362e5:d48422d462d2bcf0b9d962f150b235b9"; "_gurl_" = "sdk.open.extension.getui.com:8123"; aps = { alert = { body = "\U60a8\U9a7e\U6821\U6709\U8f66\U8f86\U7ec8\U7aef\U62a5\U8b66\U9700\U89e3\U9664\Uff0c\U8bf7\U67e5\U770b\U5e76\U5904\U7406"; title = "\U544a\U8b66\U6d88\U606f"; }; badge = 2; category = "button\U663e\U793a"; "content-available" = 1; "mutable-content" = 1; sound = default; }; 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\"}"; } */ // _gmid_对应-- taskId msgId clientID //这里使用msgid判断是否被处理【不过似乎应该用taskid?@lee,幻想着一个任务多条消息] NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSString *oldMsgId = [userDefaults objectForKey:@"remoteNotifymsgId"]; if ([msgId isEqualToString:oldMsgId]) { return; } //开始处理 [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"]; [userDefaults synchronize]; NSString *jsonStr = userInfo[@"payload"]; if ([jsonStr length] == 0) { return; } NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding]; if (data) { NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]]; pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]]; //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关 if ([pushType integerValue]>=1 && [pushType integerValue]<=5) { [self gotoPush]; }else{ //其它信息 [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]]; } } } -(void)showMsgByArertWithTitle:(NSString *)title message:(NSString *)message{ if (message.length == 0) { return; } //其它信息 UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]]; [self.window.rootViewController presentViewController:alertFind animated:true completion:nil]; } #pragma mark 推送相关跳转 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (alertView.tag == 10000) { if (buttonIndex == 1) { NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/liao-ning-jia-pei/id1225178346?l=en&mt=8"]; [[UIApplication sharedApplication]openURL:url]; } }else{ if (buttonIndex != alertView.cancelButtonIndex) { [self gotoPush]; } } } -(void)gotoPush { //1 驾考头条推送 2 新闻类型 3 话题相关信息 4 系统信息 5 预约相关 //新闻和驾考头条是一样的 switch ([pushType integerValue]) { case 1: [self goToJKTT]; break; case 2: [self goToJKTT]; break; case 3: [self goToTopic]; break; case 4: [self goToSystemNews]; break; case 5: [self goToAppoint]; break; case 6: [self gotoMyMessage]; default:{ [self gotoLoad]; } break; } } -(void)goToJKTT { NewsDetVC* vc = [[NewsDetVC alloc] init]; vc.jkttId = pushID; vc.type = @"1"; vc.isNotification = YES; MyUINavigationController *nav = [[MyUINavigationController alloc]initWithRootViewController:vc]; [myDelegate.window setRootViewController:nav]; } -(void)goToSystemNews { MyMsgVC* vc = [[MyMsgVC alloc] init]; vc.isNotification = YES; MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc]; [myDelegate.window setRootViewController:navMsg]; } -(void)goToTopic { TopicVC* vc = [[TopicVC alloc] init]; [vc setTopicId:pushID]; vc.isNotification = YES; MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc]; [myDelegate.window setRootViewController:navMsg]; } -(void)goToAppoint { AllCoachPlanVC *vc = [[AllCoachPlanVC alloc] init]; vc.isNotification = YES; MyUINavigationController *navMsg = [[MyUINavigationController alloc]initWithRootViewController:vc]; [myDelegate.window setRootViewController:navMsg]; } -(void)gotoMyMessage{ MyMsgVC* vc = [[MyMsgVC alloc] init]; vc.isNotification = YES; MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:vc]; [myDelegate.window setRootViewController:nav]; } #pragma mark - 百度地图的代理 - (void)onGetNetworkState:(int)iError { if (0 == iError) { } else{ NSLog(@"联网失败");//有时候网络不好会触发这个,从而也同时引起授权失败 } } - (void)onGetPermissionState:(int)iError { if (0 == iError) { } else { NSLog(@"授权失败"); } } #pragma mark - 广告 -(void)clickInADView { //去掉广告的代理在这里 页面传不过来 两个办法 一是将广告页面做成单例类 在这里关闭 二是这里发个通知或用kvo 在ADView中移除 ADView *ad = [ADView shareMainAD]; [ad removeImidiate]; } #pragma mark WeChatPay - (void)onResp:(BaseResp *)resp { if([resp isKindOfClass:[PayResp class]]){ //支付返回结果,实际支付结果需要去微信服务器端查询 NSString *strMsg,*strTitle = [NSString stringWithFormat:@"支付结果"]; switch (resp.errCode) { case WXSuccess: strMsg = @"支付结果:成功!"; //NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode); break; default: strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr]; //NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr); break; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,) if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) { return [WXApi handleOpenURL:url delegate:self]; } //return [WXApi handleOpenURL:url delegate:self]; return YES; } #pragma mark AliPay - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.host isEqualToString:@"safepay"]) { // 支付跳转支付宝钱包进行支付,处理支付结果 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); //NSLog(@"PaymentResult 支付结果11--><>%@",resultDic); if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) { //支付成功 [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED]; }else{ [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED]; } }]; // 授权跳转支付宝钱包进行支付,处理支付结果 [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // 解析 auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"授权结果 authCode = %@", authCode?:@""); }]; } //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,) // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) { // return [WXApi handleOpenURL:url delegate:self]; // } return YES; } // NOTE: 9.0以后使用新API接口 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { if ([url.host isEqualToString:@"safepay"]) { //跳转支付宝钱包进行支付,处理支付结果 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { //NSLog(@"result 支付结果22--><>%@",resultDic); if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) { //支付成功 [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED]; }else{ [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED]; } }]; // 授权跳转支付宝钱包进行支付,处理支付结果 [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // 解析 auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"授权结果 authCode = %@", authCode?:@""); }]; } //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,) // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) { // return [WXApi handleOpenURL:url delegate:self]; // } return YES; } #pragma mark - 广告展示 #pragma mark 检查新旧 - (void)onCheckVersion { if (![Util connectedToNetWork]){return;} NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"]; NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1225178346"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:URL]]; [request setHTTPMethod:@"POST"]; NSOperationQueue *queue=[NSOperationQueue mainQueue]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { //这个导致部分手机网络不好时候出现闪退情况 if (!data) { return; } //如果data等于nil的时候 再去解析 会发生崩溃 NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; if (!dic) { return; } NSArray *infoArray = [dic objectForKey:@"results"]; if ([infoArray count]) { NSDictionary *releaseInfo = [infoArray objectAtIndex:0]; NSString *lastVersion = [releaseInfo objectForKey:@"version"]; NSArray *last = [lastVersion componentsSeparatedByString:@"."]; NSArray *current = [currentVersion componentsSeparatedByString:@"."]; NSComparisonResult result = [last[0] compare:current[0]]; if (result == NSOrderedDescending) { [self updateVersion]; }else if(result == NSOrderedSame){ result = [last[1] compare:current[1]]; if (result == NSOrderedDescending) { [self updateVersion]; }else if(result == NSOrderedSame){ result = [last[2] compare:current[2]]; if (result == NSOrderedDescending) { [self updateVersion]; } } } } }]; } - (void)getAppAnnouncement { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *aArray=[NSMutableArray array]; NSString* method = @"getAppAnnouncement"; [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) { if (!root) { ShowMsgFailed(); return ; } if ([root[@"code"] isEqualToString:@"0"]) { NSMutableString *content = [NSMutableString string]; NSArray *strArr = root[@"data"][@"announcement"]; NSMutableArray *idArr = [NSMutableArray array]; SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:kScreenWidth - 32]; alert.customViewColor = defGreen; alert.viewText.textAlignment = NSTextAlignmentLeft; UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 64, kScreenHeight * 0.5)]; view.font = [UIFont systemFontOfSize:15]; [alert addButton:@"不再显示" actionBlock:^(void) { [[NSUserDefaults standardUserDefaults] setValue:@"doNotShowNotice" forKey:@"isShowNotice"]; NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.announcementIDArr]; [arr addObjectsFromArray:idArr]; RQ_SHARE_FUNCTION.announcementIDArr = arr.copy; }]; [[strArr.rac_sequence.signal filter:^BOOL(NSDictionary *dic) { return ![RQ_SHARE_FUNCTION.announcementIDArr containsObject:dic[@"ID"]]; }] subscribeNext:^(NSDictionary *dic) { [idArr addObject:dic[@"ID"]]; if (idArr.count > 1) { if (idArr.count == 2) { [content insertString:@"1." atIndex:0]; [content appendFormat:@"%d.%@\n\n",(int)[idArr indexOfObject:dic[@"ID"]] + 1,dic[@"VALUE"]]; }else { [content appendFormat:@"%d.%@\n\n",(int)[idArr indexOfObject:dic[@"ID"]] + 1,dic[@"VALUE"]]; } }else { [content appendFormat:@"%@\n\n",dic[@"VALUE"]]; } [[NSUserDefaults standardUserDefaults] setValue:@"ShowNotice" forKey:@"isShowNotice"]; } completed:^{ dispatch_main_async_safe(^{ if (content.length == 0) { return; } view.text = content.mutableCopy; CGFloat textHeight = [view.text heightForWid:view.width Font:15]; view.height = (textHeight > kScreenHeight/2)? kScreenHeight/2 : textHeight; [alert addCustomView:view]; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isKindOfClass:[NSString class]] && [[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isEqualToString:@"doNotShowNotice"]) { return; }else { [alert showInfo:@"公告" subTitle:@"" closeButtonTitle:@"确定" duration:0.0f]; } }) }]; } else { ShowMsg(root[@"msg"]); return ; } }]; } - (void)getAppAnnouncementOne { // NSDictionary *dic = @{}; // dic = @{ // @"TIME":@"5",@"ID":@"46",@"VALUE":@"告学员学车书",@"URL":@"http://lnxzzfile.oss-cn-beijing.aliyuncs.com//tms/student/contract/202111/appGG20220121001.pdf" // }; // if (dic) { // self.announcementId = dic[@"ID"]; // NSString *key1 = [NSString stringWithFormat:@"getAppAnnouncementShowOne%@",self.announcementId]; // NSString *key2 = [NSString stringWithFormat:@"getAppAnnouncementShowTwo%@",self.announcementId]; // if ([[RQPreferenceSettingHelper objectForKey:key1] boolValue] && [[RQPreferenceSettingHelper objectForKey:key2] boolValue]) { // // } else { // RQWebViewViewController *vc = [[RQWebViewViewController alloc] init]; // vc.webType = WebTypeStuLearnBook; // vc.titleStr = dic[@"VALUE"]; // vc.url = dic[@"URL"]; // vc.countStr = dic[@"TIME"]; // vc.modalPresentationStyle = UIModalPresentationFullScreen; // [RQ_SHARE_FUNCTION.topViewController rq_pushViewController:vc]; // } // } // return; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *aArray=[NSMutableArray array]; NSString* method = @"getAppAnnouncement2"; [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) { if (!root) { ShowMsgFailed(); return ; } if ([root[@"code"] isEqualToString:@"0"]) { NSArray *announcementArr = root[@"data"][@"announcement"]; if (announcementArr && announcementArr.count > 0) { NSDictionary *dic = announcementArr.firstObject; if (dic) { self.announcementId = dic[@"ID"]; NSString *key1 = [NSString stringWithFormat:@"getAppAnnouncementShowOne%@",self.announcementId]; NSString *key2 = [NSString stringWithFormat:@"getAppAnnouncementShowTwo%@",self.announcementId]; if ([[RQPreferenceSettingHelper objectForKey:key1] boolValue] && [[RQPreferenceSettingHelper objectForKey:key2] boolValue]) { } else { RQWebViewViewController *vc = [[RQWebViewViewController alloc] init]; vc.webType = WebTypeStuLearnBook; vc.titleStr = dic[@"VALUE"]; vc.url = dic[@"URL"]; vc.countStr = dic[@"TIME"]; vc.modalPresentationStyle = UIModalPresentationFullScreen; [RQ_SHARE_FUNCTION.topViewController rq_pushViewController:vc]; } } } } else { ShowMsg(root[@"msg"]); return ; } }]; } /// http://127.0.0.1:8083/lnwebservice_mysql/edu/getAppCompetence?ts=1645718529359&sign=ec124266ee1db3cec69d7fc4dc98a740&user=xzz&imsi=460064990040819 - (void)getAppCompetence { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *aArray=[NSMutableArray array]; NSString* method = @"getAppCompetence"; [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) { if (!root) { ShowMsgFailed(); return ; } // {"body":"","code":"0","data":{"exerciseState":"0","exerciseMsg":"题库升级中..."},"msg":"成功","result":""} // exerciseState 0不开放,1开放 if ([root[@"code"] isEqualToString:@"0"]) { NSDictionary *dic = root[@"data"]; if (dic) { [RQPreferenceSettingHelper setObject:dic[@"exerciseState"] forKey:@"exerciseState"]; [RQPreferenceSettingHelper setObject:dic[@"exerciseMsg"] forKey:@"exerciseMsg"]; #if DEBUG [RQPreferenceSettingHelper setObject:@"1" forKey:@"exerciseState"]; #endif } } else { ShowMsg(root[@"msg"]); return ; } }]; } - (void)updateVersion { [RQ_Question_Module rq_showAppUpdateView]; // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新提示" message:@"有新的版本发布,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil]; // alert.tag = 10000; // [alert show]; } #pragma mark 欢迎页面 - (void)makeLaunchView { NSArray* images = @[@"welcom_page_1.jpg",@"welcom_page_2.jpg",@"welcom_page_3.jpg" ];//@"welcom_page_4.jpg" scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height)]; scroll.bounces = NO; /**跳到最后页的下一页,也会欢迎结束 */ [scroll setContentSize:CGSizeMake(kSize.width* images.count+10, 0)]; [scroll setBackgroundColor:[UIColor whiteColor]]; [scroll setShowsHorizontalScrollIndicator:NO]; [scroll setDelegate:self]; scroll.pagingEnabled = YES; UIViewController *vc = [UIViewController new]; [vc.view addSubview:scroll]; // slide_right 图片 [self.window setRootViewController:vc]; pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, kSize.height-50, kSize.width, 20)]; pageControl.userInteractionEnabled = NO; // pageControl.pageIndicatorTintColor = [UIColor blackColor]; // pageControl.currentPageIndicatorTintColor = [UIColor whiteColor]; pageControl.numberOfPages = scroll.contentSize.width/scroll.frame.size.width; [vc.view addSubview:pageControl]; UIImageView *iv; for (int i =0; i kSize.width * 2) { [self gotoChooseLib]; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { pageControl.currentPage = scrollView.contentOffset.x/scrollView.frame.size.width; } - (void)test { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; NSString* method = @"doGetStudentActiveKhStatus"; [arr addPro:@"stuIdCard" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? defUser.sfzmhm : @"362324199302156513"]; [arr addPro:@"stuOutId" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? [NSString stringWithFormat:@"%@",defUser.userDict[@"outId"]] : @"2101000519225"]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { if (!root) { ShowMsgFailed(); return ; } if ([root[@"code"] isEqualToString:@"0"]) { ShowMsg(root[@"body"]); return; } else { ShowMsg(root[@"body"]); return; } }]; } /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { // 可以这么写 if (self.allowOrentitaionRotation) { return UIInterfaceOrientationMaskAllButUpsideDown; } return UIInterfaceOrientationMaskPortrait; } - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler{ // 通用链接 if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { NSURL *url = userActivity.webpageURL; NSLog(@"通用链接 :%@", url); if ([[url absoluteString] containsString:@"wx606fa102dbc4b8ab"]) { return [WXApi handleOpenUniversalLink:userActivity delegate:self]; } else if ([[url absoluteString] containsString:@"https://app.jppt.com.cn/JSJPStudent/"]) { return YES; } return NO; } return NO; } #pragma mark - 在初始化UI之前配置 - (void)rq_configureApplication:(UIApplication *)application initialParamsBeforeInitUI:(NSDictionary *)launchOptions { // 配置键盘 // [self rq_configureKeyboardManager]; // 配置文件夹 // [self rq_configureApplicationDirectory]; // 配置FMDB // [self rq_configureFMDB]; // 配置流音乐播放 // [DOUAudioStreamer setOptions:[DOUAudioStreamer options] | DOUAudioStreamerRequireSHA256]; // 配置微信 // [self rq_configureWechat]; [self rq_configureNetState]; [self getConfigKey]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.is_Online_Media = [x boolValue]; }]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media_Image"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.is_Online_Media_Image = [x boolValue]; }]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"is_Online_Media_Video"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.is_Online_Media_Video = [x boolValue]; }]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_HY_FACE_NUM"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.LN_HY_FACE_NUM = [x integerValue]; }]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_NET_EDU_FACE_NUM"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.LN_NET_EDU_FACE_NUM = [x integerValue]; }]; [[RQ_HTTP_Service getConfigKeyWithDictType:@"LN_SHEQU_OPEN"] subscribeNext:^(id _Nullable x) { RQ_COMMON_MANAGER.LN_SHEQU_OPEN = [x boolValue]; }]; [[RQ_HTTP_Service getOldFaceHistoryListList] subscribeNext:^(NSArray *oldFaceHistoryListListArr) { NSArray *arr = [[oldFaceHistoryListListArr.rac_sequence.signal filter:^BOOL(RQDictInfoModel *dictInfoModel) { return [dictInfoModel.status isEqualToString:@"0"]; }].toArray.rac_sequence.signal map:^id _Nullable(RQDictInfoModel *dictInfoModel) { return dictInfoModel.dictValue; }].toArray; RQ_COMMON_MANAGER.oldFaceHistoryListListArr = RQObjectIsNil(arr)? @[] : arr; }]; [[RQ_HTTP_Service getChapterList] subscribeNext:^(id _Nullable x) { }]; /// 初始化百度人脸识别SDK [self initDBFaceSDK]; /// 定位权限请求 [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location) { }]; if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) { [self rq_AD]; if (RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN) { [RQ_AD_MODULE loadAdWithAdType:GromoreAdTypeSplash customView:nil]; } } } - (void)rq_configureNetState { /// 开启网络监测 [[ZFReachabilityManager sharedManager] startMonitoring]; [[ZFReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(ZFReachabilityStatus status) { }]; } // 配置键盘管理器 - (void)rq_configureKeyboardManager { IQKeyboardManager.sharedManager.enable = YES; IQKeyboardManager.sharedManager.enableAutoToolbar = NO; IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = YES; } // 配置文件夹 - (void)rq_configureApplicationDirectory { /// 创建doc [RQFileManager createDirectoryAtPath:RQWeChatDocDirPath()]; /// 创建cache [RQFileManager createDirectoryAtPath:RQWeChatCacheDirPath()]; NSLog(@"RQWeChatDocDirPath is [ %@ ] \n RQWeChatCacheDirPath is [ %@ ]" , RQWeChatDocDirPath() , RQWeChatCacheDirPath()); } /// 配置FMDB - (void)rq_configureFMDB { // FMDatabaseQueue *databaseQueue = [[FMDatabaseQueue alloc] init]; // [databaseQueue inDatabase:^(FMDatabase *db) { // NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey]; // if (![version isEqualToString:RQ_APP_VERSION]) { // NSString *path = [[NSBundle mainBundle] pathForResource:@"question20210722" ofType:@"db"]; // NSString *sql = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; // /// 执行文件 // if (![db executeStatements:sql]) { // RQLogLastError(db); // } // } // }]; NSFileManager *fileManager =[NSFileManager defaultManager]; NSError*error; if ([fileManager fileExistsAtPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"question20210722.db"]]]== NO) { NSString*resourcePath =[[NSBundle mainBundle] pathForResource:@"question20210722" ofType:@"db"]; [fileManager copyItemAtPath:resourcePath toPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"question20210722.db"]] error:&error]; } if (RQ_USER_MANAGER.isLogin) { [RQ_UPDATE_LOCALDATA_MANAGER updateLocalCollectionListWithComplete:nil]; [RQ_UPDATE_LOCALDATA_MANAGER updateLocalWrongListWithComplete:nil]; } } - (void)rq_configureWechat { /// 向微信注册 [RQ_WECHAT_MANAGER initWechatManager]; } #pragma mark - 在初始化UI之后配置 - (void)rq_configureApplication:(UIApplication *)application initialParamsAfterInitUI:(NSDictionary *)launchOptions { /// 配置ActionSheet [LCActionSheet rq_configureActionSheet]; /// 预先配置平台信息 // [SBUMengService configureUMengPreDefinePlatforms]; @weakify(self); /// 监听切换根控制器的通知 [[RQNotificationCenter rac_addObserverForName:RQSwitchRootViewControllerNotification object:nil] subscribeNext:^(NSNotification * note) { /// 这里切换根控制器 @strongify(self); // 重置rootViewController RQSwitchRootViewControllerFromType fromType = [note.userInfo[RQSwitchRootViewControllerUserInfoKey] integerValue]; NSLog(@"fromType is %zd" , fromType); /// 切换根控制器 [self.services resetRootViewModel:[self rq_createInitialViewModel]]; /// 切换了根控制器,切记需要将指示器 移到window的最前面 #if defined(DEBUG)||defined(_DEBUG) [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]]; #endif }]; /// 配置H5 // [SBConfigureManager configure]; } #pragma mark - 调试(DEBUG)模式下的工具条 - (void)rq_configDebugModelTools { /// 显示FPS [[JPFPSStatus sharedInstance] open]; /// 打开调试按钮 [RQDebugTouchView sharedInstance]; /// RQ Fixed: 切换了根控制器,切记需要将指示器 移到window的最前面 [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]]; } #pragma mark - 创建根控制器 - (RQBaseViewModel *)rq_createInitialViewModel { // The user has logged-in. // NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey]; /// 版本不一样就先走 新特性界面 // if (![version isEqualToString:RQ_APP_VERSION]){ // return [[RQNewFeatureViewModel alloc] initWithServices:self.services params:nil]; // }else{ /// 这里判断一下 // if ([SAMKeychain rawLogin] && self.services.client.currentUser) { /// 有账号+有用户数据 /// 已经登录,跳转到主页 return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil]; // }else if(self.services.client.currentUser){ /// 没账号+有用户数据 /// 跳转到账户登录页面 // return [[RQAccountLoginViewModel alloc] initWithServices:self.services params:nil]; // }else{ /// 第一次使用微信 // return [[RQBootLoginViewModel alloc] initWithServices:self.services params:nil]; // } // } } - (void)getVideoTypeList { [[RQ_HTTP_Service getTreeList] subscribeNext:^(NSArray * dataArr) { if (!RQObjectIsNil(dataArr)) { RQ_COMMON_MANAGER.treeListArr = dataArr; } }]; // NSMutableArray *arr = [NSMutableArray array]; // [arr addPro:@"videoTypeId" Value:@"20"]; // // NSString *method= @"/open-api/teachingVideo/info/getTeachingVideoByTypeId"; // // [jiaPeiManager requestGetAnythingWithURL:method array:arr completion:^(NSDictionary *dict) { // // }]; } #pragma mark - initDBFaceSDK - (void)initDBFaceSDK { [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"SoundMode"]; [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"LiveMode"]; [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"ByOrder"]; [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"checkAgreeBtn"]; NSString* licensePath = [NSString stringWithFormat:@"%@.%@", FACE_LICENSE_NAME, FACE_LICENSE_SUFFIX ]; [[FaceSDKManager sharedInstance] setLicenseID:FACE_LICENSE_ID andLocalLicenceFile:licensePath andRemoteAuthorize:false]; NSLog(@"canWork = %d",[[FaceSDKManager sharedInstance] canWork]); NSLog(@"version = %@",[[FaceSDKManager sharedInstance] getVersion]); [self initSDK]; [self initLivenesswithList]; } - (void)initSDK { if (![[FaceSDKManager sharedInstance] canWork]){ NSLog(@"授权失败,请检测ID 和 授权文件是否可用"); return; } // 初始化SDK配置参数,可使用默认配置 // 设置最小检测人脸阈值 [[FaceSDKManager sharedInstance] setMinFaceSize:200]; // 设置截取人脸图片高 [[FaceSDKManager sharedInstance] setCropFaceSizeWidth:480]; // 设置截取人脸图片宽 [[FaceSDKManager sharedInstance] setCropFaceSizeHeight:640]; // 设置人脸遮挡阀值 [[FaceSDKManager sharedInstance] setOccluThreshold:0.5]; // 设置亮度阀值 [[FaceSDKManager sharedInstance] setMinIllumThreshold:40]; [[FaceSDKManager sharedInstance] setMaxIllumThreshold:240]; // 设置图像模糊阀值 [[FaceSDKManager sharedInstance] setBlurThreshold:0.3]; // 设置头部姿态角度 [[FaceSDKManager sharedInstance] setEulurAngleThrPitch:10 yaw:10 roll:10]; // 设置人脸检测精度阀值 [[FaceSDKManager sharedInstance] setNotFaceThreshold:0.6]; // 设置抠图的缩放倍数 [[FaceSDKManager sharedInstance] setCropEnlargeRatio:2.5]; // 设置照片采集张数 [[FaceSDKManager sharedInstance] setMaxCropImageNum:3]; // 设置超时时间 [[FaceSDKManager sharedInstance] setConditionTimeout:15]; // 设置开启口罩检测,非动作活体检测可以采集戴口罩图片 [[FaceSDKManager sharedInstance] setIsCheckMouthMask:true]; // 设置开启口罩检测情况下,非动作活体检测口罩过滤阈值,默认0.8 不需要修改 [[FaceSDKManager sharedInstance] setMouthMaskThreshold:0.8f]; // 设置原始图缩放比例 [[FaceSDKManager sharedInstance] setImageWithScale:0.8f]; // 设置图片加密类型,type=0 基于base64 加密;type=1 基于百度安全算法加密 [[FaceSDKManager sharedInstance] setImageEncrypteType:0]; // 初始化SDK功能函数 [[FaceSDKManager sharedInstance] initCollect]; // 设置人脸过远框比例 [[FaceSDKManager sharedInstance] setMinRect:0.4]; /// 设置用户设置的配置参数 [BDFaceAdjustParamsTool setDefaultConfig]; } - (void)initLivenesswithList { // 默认活体检测打开,顺序执行 /* 添加当前默认的动作,是否需要按照顺序,动作活体的数量(设置页面会根据这个numOfLiveness来判断选择了几个动作) */ [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveEye)]; [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveMouth)]; [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYawRight)]; [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYawLeft)]; [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLivePitchUp)]; [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLivePitchDown)]; // [BDFaceLivingConfigModel.sharedInstance.liveActionArray addObject:@(FaceLivenessActionTypeLiveYaw)]; BDFaceLivingConfigModel.sharedInstance.isByOrder = NO; BDFaceLivingConfigModel.sharedInstance.numOfLiveness = 3; } - (void) destorySDK { // 销毁SDK功能函数 [[FaceSDKManager sharedInstance] uninitCollect]; } - (void)getConfigKey { [[RQ_HTTP_Service getYyxcSet] subscribeNext:^(NSArray *setArr) { [setArr.rac_sequence.signal subscribeNext:^(RQDictInfoModel *dictInfoModel) { if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_OPEN"]) { RQ_COMMON_MANAGER.YYXC_AD_OPEN = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_SPLASH_AD_OPEN"]) { RQ_COMMON_MANAGER.YYXC_SPLASH_AD_OPEN = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_NATIVE_AD_OPEN"]) { RQ_COMMON_MANAGER.YYXC_NATIVE_AD_OPEN = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_BANNER_AD_OPEN"]) { RQ_COMMON_MANAGER.YYXC_BANNER_AD_OPEN = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_SERVICE_OPEN"]) { RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN = [dictInfoModel.dictValue boolValue]; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_TIME1"]) { RQ_COMMON_MANAGER.YYXC_AD_TIME1 = dictInfoModel.dictValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"YYXC_AD_TIME2"]) { RQ_COMMON_MANAGER.YYXC_AD_TIME2 = dictInfoModel.dictValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media"]) { RQ_COMMON_MANAGER.is_Online_Media = dictInfoModel.dictValue.boolValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media_Image"]) { RQ_COMMON_MANAGER.is_Online_Media_Image = dictInfoModel.dictValue.boolValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"is_Online_Media_Video"]) { RQ_COMMON_MANAGER.is_Online_Media_Video = dictInfoModel.dictValue.boolValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_HY_FACE_NUM"]) { RQ_COMMON_MANAGER.LN_HY_FACE_NUM = dictInfoModel.dictValue.integerValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_NET_EDU_FACE_NUM"]) { RQ_COMMON_MANAGER.LN_NET_EDU_FACE_NUM = dictInfoModel.dictValue.integerValue; } else if ([dictInfoModel.dictLabel isEqualToString:@"LN_SHEQU_OPEN"]) { RQ_COMMON_MANAGER.LN_SHEQU_OPEN = dictInfoModel.dictValue.integerValue; } }]; }]; } //- (void)setThirtyPartySdk { // if ([self isFirstAppLoad]) { // // 记录是否第一次启动 // [self writeAppLoad]; // // 获取idfa权限 建议启动就获取权限 不获取权限会影响收益 // if (@available(iOS 14.0, *)) { // [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { // // }]; // } // // 用户同意隐私后 初始化 // [self rq_GDTSDK]; // }else { // [self rq_GDTSDK]; // } //} - (void)writeAppLoad { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:@"yes" forKey:@"isFirstLoad"]; [userDefault synchronize]; } - (BOOL)isFirstAppLoad { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; if ([[userDefault objectForKey:@"isFirstLoad"] isEqualToString:@"yes"]) { return NO; } return YES; } - (void)rq_AD { #pragma mark 设定流量分组 // [self userSegmentSetting]; #pragma mark 隐私配置设置 [self privateSetting]; #pragma mark 初始化Gromore SDK if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { [self initGromoreSDK]; }]; } else { [self initGromoreSDK]; } } /// 初始化Gromore SDK - (void)initGromoreSDK { // Gromore SDK初始化方法 [ABUAdSDKManager setupSDKWithAppId:@"5377374" config:^ABUUserConfig *(ABUUserConfig *c) { // 打开日志开关,线上环境请关闭 c.logEnable = YES; c.testMode = YES; // 设定自定义IDFA,根据实际情况设定 c.customIDFA = @"00000000-0000-0000-0000-000000000001"; return c; }]; ABUSplashAd *splashAd = [[ABUSplashAd alloc] initWithAdUnitID:@""]; splashAd.rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController]; ABUFullscreenVideoAd *fullscreenVideoAd = [[ABUFullscreenVideoAd alloc] initWithAdUnitID:@""]; fullscreenVideoAd.mutedIfCan = YES;//静音 // 新接口,用于传入首次预缓存的广告对象 // [ABUAdSDKManager preloadAdsWithInfos:@[splashAd, fullscreenVideoAd] andInterval:2 andConcurrent:2]; } /// 流量分组设定 - (void)userSegmentSetting { ABUUserInfoForSegment *segment = [[ABUUserInfoForSegment alloc] init]; segment.user_id = @"Please enter your user's Id"; segment.user_value_group = @"group1"; segment.age = 19; segment.gender = ABUUserInfo_Gender_Male; segment.channel = @"Apple"; segment.sub_channel = @"Apple store"; segment.customized_id = @{@(1):@"345",// key非string,不合规 @"key2":@"good",// 合规,上报 @"key3":@(1),// value非string,不合规 @"key4":@"123aA-_",// 合规,上报 @"key5":@"123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_1",// 长度超100,不合规 @"key6":@"123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_123456aA-_",// 合规,上报 @"key7":@"123aA-_*",// value包含特殊字符,不合规 }; [ABUAdSDKManager setUserInfoForSegment:segment]; } /// 隐私设置 - (void)privateSetting { [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyForbiddenIDFA andValue:@(0)]; [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyForbiddenCAID andValue:@(0)]; [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLimitPersonalAds andValue:@(0)]; [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLongitude andValue:@(115.7)]; [ABUPrivacyConfig setPrivacyWithKey:kABUPrivacyLatitude andValue:@(39.4)]; } @end