AppDelegate.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 <ZFPlayer/ZFLandscapeRotationManager.h>
  10. #import <UMCommon/UMCommon.h>
  11. #import "RQYDTXCQuestionModule.h"
  12. @interface AppDelegate ()
  13. /// APP管理的导航栏的堆栈
  14. @property (nonatomic, readwrite, strong) RQNavigationControllerStack *navigationControllerStack;
  15. /// APP的服务层
  16. @property (nonatomic, readwrite, strong) RQViewModelServicesImpl *services;
  17. @end
  18. @implementation AppDelegate
  19. @synthesize window;
  20. #pragma mark- 获取appDelegate
  21. + (AppDelegate *)sharedDelegate {
  22. return (AppDelegate *)[[UIApplication sharedApplication] delegate];
  23. }
  24. //程序开始
  25. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  26. [super application:application didFinishLaunchingWithOptions:launchOptions];
  27. [self configureSDKs];
  28. /// 初始化UI之前配置
  29. [self rq_configureApplication:application initialParamsBeforeInitUI:launchOptions];
  30. // Config Service
  31. self.services = [[RQViewModelServicesImpl alloc] init];
  32. // Config Nav Stack
  33. self.navigationControllerStack = [[RQNavigationControllerStack alloc] initWithServices:self.services];
  34. // Configure Window
  35. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  36. self.window.backgroundColor = [UIColor whiteColor];
  37. // 重置rootViewController
  38. [self.services resetRootViewModel:[self rq_createInitialViewModelWithFromType:RQSwitchRootViewControllerFromTypeLogin]];
  39. // 让窗口可见
  40. [self.window makeKeyAndVisible];
  41. // 初始化UI后配置
  42. [self rq_configureApplication:application initialParamsAfterInitUI:launchOptions];
  43. #if defined(DEBUG)||defined(_DEBUG)
  44. /// 调试模式
  45. [self rq_configDebugModelTools];
  46. [QMUIConsole sharedInstance].canShow = NO;
  47. #endif
  48. // Save the application version info. must write last
  49. [[NSUserDefaults standardUserDefaults] setValue:RQ_APP_VERSION forKey:RQApplicationVersionKey];
  50. [[NSUserDefaults standardUserDefaults] synchronize];
  51. [RQ_AD_MANAGER loadMineSplashAd];
  52. return YES;
  53. }
  54. //配置第三方 SDK
  55. - (void)configureSDKs{
  56. //友盟 UM_APPKEY
  57. [UMConfigure setLogEnabled:YES];
  58. [UMConfigure initWithAppkey:UM_APPKEY channel:@"App Store"];
  59. // NSLog(@"UMAPM version:%@",[UMCrashConfigure getVersion]);
  60. }
  61. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  62. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  63. ZFInterfaceOrientationMask orientationMask = [ZFLandscapeRotationManager supportedInterfaceOrientationsForWindow:window];
  64. if (orientationMask != ZFInterfaceOrientationMaskUnknow) {
  65. return (UIInterfaceOrientationMask)orientationMask;
  66. }
  67. UIViewController *current_VC = RQControllerHelper.currentViewController;
  68. if([current_VC isKindOfClass:[NYExaminationViewController class]]||
  69. [current_VC isKindOfClass:[NYExaminationRoomViewController class]]){
  70. return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortrait;
  71. }
  72. /// 这里是非播放器VC支持的方向
  73. return UIInterfaceOrientationMaskPortrait;
  74. }
  75. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  76. // 通用链接
  77. if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  78. NSURL *url = userActivity.webpageURL;
  79. NSLog(@"通用链接 :%@", url);
  80. if ([[url absoluteString] containsString:RQ_WECHAT_MANAGER.appID]) {
  81. // return [RQ_WECHAT_MANAGER kplchihandleLrvm:[url absoluteString]];
  82. return [WXApi handleOpenUniversalLink:userActivity
  83. delegate:RQ_WECHAT_MANAGER];
  84. } else if ([[url absoluteString] containsString:@"https://app.jppt.com.cn/JSJPStudent/"]) {
  85. return YES;
  86. }
  87. return NO;
  88. }
  89. return NO;
  90. }
  91. // NOTE: 9.0以后使用新API接口
  92. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
  93. // if ([url.host isEqualToString:@"safepay"]) {
  94. // // 支付跳转支付宝钱包进行支付,处理支付结果
  95. // [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  96. // NSLog(@"result = %@",resultDic);
  97. // }];
  98. //
  99. // // 授权跳转支付宝钱包进行支付,处理支付结果
  100. // [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
  101. // NSLog(@"result = %@",resultDic);
  102. // // 解析 auth code
  103. // NSString *result = resultDic[@"result"];
  104. // NSString *authCode = nil;
  105. // if (result.length>0) {
  106. // NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  107. // for (NSString *subResult in resultArr) {
  108. // if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  109. // authCode = [subResult substringFromIndex:10];
  110. // break;
  111. // }
  112. // }
  113. // }
  114. // NSLog(@"授权结果 authCode = %@", authCode?:@"");
  115. // }];
  116. // }
  117. ///
  118. if ([[url absoluteString] containsString:RQ_WECHAT_MANAGER.appID]) {
  119. // return [RQ_WECHAT_MANAGER kplchihandleLrvm:[url absoluteString]];
  120. return [WXApi handleOpenURL:url delegate:RQ_WECHAT_MANAGER];
  121. }
  122. return YES;
  123. }
  124. #pragma mark - 在初始化UI之前配置
  125. - (void)rq_configureApplication:(UIApplication *)application initialParamsBeforeInitUI:(NSDictionary *)launchOptions {
  126. // 配置广告
  127. [RQ_AD_MANAGER rq_configureADSuiSDK];
  128. // 配置文件夹
  129. [self rq_configureApplicationDirectory];
  130. // 配置FMDB
  131. [self rq_configureFMDB];
  132. // 配置微信
  133. [self rq_configureWechat];
  134. // 配置键盘
  135. [self rq_configureKeyboardManager];
  136. }
  137. // 配置文件夹
  138. - (void)rq_configureApplicationDirectory {
  139. /// 创建doc
  140. [RQFileManager createDirectoryAtPath:RQWeChatDocDirPath()];
  141. /// 创建cache
  142. [RQFileManager createDirectoryAtPath:RQWeChatCacheDirPath()];
  143. NSLog(@"RQWeChatDocDirPath is [ %@ ] \n RQWeChatCacheDirPath is [ %@ ]" , RQWeChatDocDirPath() , RQWeChatCacheDirPath());
  144. }
  145. /// 配置FMDB
  146. - (void)rq_configureFMDB {
  147. }
  148. /// 检查题库版本
  149. - (void)rq_configureQuestionUpdate {
  150. NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  151. if ([version isEqualToString:RQ_APP_VERSION]) {
  152. [RQ_YDTQuestion_Module rq_updateQuestion];
  153. }
  154. }
  155. - (void)rq_configureWechat {
  156. /// 向微信注册
  157. [RQ_WECHAT_MANAGER initWechatManager];
  158. }
  159. // 配置键盘管理器
  160. - (void)rq_configureKeyboardManager {
  161. IQKeyboardManager.sharedManager.enable = YES;
  162. IQKeyboardManager.sharedManager.enableAutoToolbar = NO;
  163. IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = YES;
  164. }
  165. #pragma mark - 在初始化UI之后配置
  166. - (void)rq_configureApplication:(UIApplication *)application initialParamsAfterInitUI:(NSDictionary *)launchOptions {
  167. /// 配置ActionSheet
  168. [LCActionSheet rq_configureActionSheet];
  169. /// 预先配置平台信息
  170. // [SBUMengService configureUMengPreDefinePlatforms];
  171. @weakify(self);
  172. /// 监听切换根控制器的通知
  173. [[RQNotificationCenter rac_addObserverForName:RQSwitchRootViewControllerNotification object:nil] subscribeNext:^(NSNotification * note) {
  174. /// 这里切换根控制器
  175. @strongify(self);
  176. // 重置rootViewController
  177. RQSwitchRootViewControllerFromType fromType = [note.userInfo[RQSwitchRootViewControllerUserInfoKey] integerValue];
  178. NSLog(@"fromType is %zd" , fromType);
  179. /// 切换根控制器
  180. [self.services resetRootViewModel:[self rq_createInitialViewModelWithFromType:fromType]];
  181. /// 切换了根控制器,切记需要将指示器 移到window的最前面
  182. #if defined(DEBUG)||defined(_DEBUG)
  183. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  184. #endif
  185. }];
  186. /// 配置H5
  187. // [SBConfigureManager configure];
  188. /// 检查题库版本
  189. [self rq_configureQuestionUpdate];
  190. [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil];
  191. }
  192. #pragma mark - 调试(DEBUG)模式下的工具条
  193. - (void)rq_configDebugModelTools {
  194. /// 打开调试按钮
  195. [RQDebugTouchView sharedInstance];
  196. /// RQ Fixed: 切换了根控制器,切记需要将指示器 移到window的最前面
  197. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  198. }
  199. #pragma mark - 创建根控制器
  200. - (RQBaseViewModel *)rq_createInitialViewModelWithFromType:(RQSwitchRootViewControllerFromType)fromType {
  201. // The user has logged-in.
  202. NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  203. /// 版本不一样就先走 新特性界面
  204. if (![version isEqualToString:RQ_APP_VERSION]) {
  205. return [[RQNewFeatureViewModel alloc] initWithServices:self.services params:@{RQViewCommonValueKey : @"2022.05.13appƬͷ_x264"}];
  206. } else {
  207. switch (fromType) {
  208. case RQSwitchRootViewControllerFromTypeCancelLogin:
  209. return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  210. default: {
  211. /// 这里判断一下
  212. // if (RQStringIsEmpty(RQ_YDTQuestion_Module.car_type)) {
  213. // return [[RQChooseExLibViewModel alloc] initWithServices:self.services params:@{RQViewCommonValueKey : @(YES)}];
  214. // } else {
  215. return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  216. // if ([SAMKeychain rawLogin] && RQ_USER_MANAGER.currentUser) {
  217. // /// 有账号+有用户数据
  218. // /// 已经登录,跳转到主页
  219. // return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  220. // } else if(RQ_USER_MANAGER.currentUser) {
  221. // /// 没账号+有用户数据
  222. // /// 跳转到账户登录页面
  223. // return [[RQLoginViewModel alloc] initWithServices:self.services params:nil];
  224. // } else {
  225. // /// 第一次使用
  226. // return [[RQLoginViewModel alloc] initWithServices:self.services params:nil];
  227. // }
  228. // }
  229. }
  230. }
  231. }
  232. }
  233. @end