AppDelegate.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. /// 这里是非播放器VC支持的方向
  68. return UIInterfaceOrientationMaskPortrait;
  69. }
  70. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  71. // 通用链接
  72. if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  73. NSURL *url = userActivity.webpageURL;
  74. NSLog(@"通用链接 :%@", url);
  75. if ([[url absoluteString] containsString:RQ_WECHAT_MANAGER.appID]) {
  76. // return [RQ_WECHAT_MANAGER kplchihandleLrvm:[url absoluteString]];
  77. return [WXApi handleOpenUniversalLink:userActivity
  78. delegate:RQ_WECHAT_MANAGER];
  79. } else if ([[url absoluteString] containsString:@"https://app.jppt.com.cn/JSJPStudent/"]) {
  80. return YES;
  81. }
  82. return NO;
  83. }
  84. return NO;
  85. }
  86. // NOTE: 9.0以后使用新API接口
  87. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
  88. // if ([url.host isEqualToString:@"safepay"]) {
  89. // // 支付跳转支付宝钱包进行支付,处理支付结果
  90. // [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  91. // NSLog(@"result = %@",resultDic);
  92. // }];
  93. //
  94. // // 授权跳转支付宝钱包进行支付,处理支付结果
  95. // [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
  96. // NSLog(@"result = %@",resultDic);
  97. // // 解析 auth code
  98. // NSString *result = resultDic[@"result"];
  99. // NSString *authCode = nil;
  100. // if (result.length>0) {
  101. // NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  102. // for (NSString *subResult in resultArr) {
  103. // if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  104. // authCode = [subResult substringFromIndex:10];
  105. // break;
  106. // }
  107. // }
  108. // }
  109. // NSLog(@"授权结果 authCode = %@", authCode?:@"");
  110. // }];
  111. // }
  112. ///
  113. if ([[url absoluteString] containsString:RQ_WECHAT_MANAGER.appID]) {
  114. // return [RQ_WECHAT_MANAGER kplchihandleLrvm:[url absoluteString]];
  115. return [WXApi handleOpenURL:url delegate:RQ_WECHAT_MANAGER];
  116. }
  117. return YES;
  118. }
  119. #pragma mark - 在初始化UI之前配置
  120. - (void)rq_configureApplication:(UIApplication *)application initialParamsBeforeInitUI:(NSDictionary *)launchOptions {
  121. // 配置广告
  122. [RQ_AD_MANAGER rq_configureADSuiSDK];
  123. // 配置文件夹
  124. [self rq_configureApplicationDirectory];
  125. // 配置FMDB
  126. [self rq_configureFMDB];
  127. // 配置微信
  128. [self rq_configureWechat];
  129. // 配置键盘
  130. [self rq_configureKeyboardManager];
  131. }
  132. // 配置文件夹
  133. - (void)rq_configureApplicationDirectory {
  134. /// 创建doc
  135. [RQFileManager createDirectoryAtPath:RQWeChatDocDirPath()];
  136. /// 创建cache
  137. [RQFileManager createDirectoryAtPath:RQWeChatCacheDirPath()];
  138. NSLog(@"RQWeChatDocDirPath is [ %@ ] \n RQWeChatCacheDirPath is [ %@ ]" , RQWeChatDocDirPath() , RQWeChatCacheDirPath());
  139. }
  140. /// 配置FMDB
  141. - (void)rq_configureFMDB {
  142. }
  143. /// 检查题库版本
  144. - (void)rq_configureQuestionUpdate {
  145. NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  146. if ([version isEqualToString:RQ_APP_VERSION]) {
  147. [RQ_YDTQuestion_Module rq_updateQuestion];
  148. }
  149. }
  150. - (void)rq_configureWechat {
  151. /// 向微信注册
  152. [RQ_WECHAT_MANAGER initWechatManager];
  153. }
  154. // 配置键盘管理器
  155. - (void)rq_configureKeyboardManager {
  156. IQKeyboardManager.sharedManager.enable = YES;
  157. IQKeyboardManager.sharedManager.enableAutoToolbar = NO;
  158. IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = YES;
  159. }
  160. #pragma mark - 在初始化UI之后配置
  161. - (void)rq_configureApplication:(UIApplication *)application initialParamsAfterInitUI:(NSDictionary *)launchOptions {
  162. /// 配置ActionSheet
  163. [LCActionSheet rq_configureActionSheet];
  164. /// 预先配置平台信息
  165. // [SBUMengService configureUMengPreDefinePlatforms];
  166. @weakify(self);
  167. /// 监听切换根控制器的通知
  168. [[RQNotificationCenter rac_addObserverForName:RQSwitchRootViewControllerNotification object:nil] subscribeNext:^(NSNotification * note) {
  169. /// 这里切换根控制器
  170. @strongify(self);
  171. // 重置rootViewController
  172. RQSwitchRootViewControllerFromType fromType = [note.userInfo[RQSwitchRootViewControllerUserInfoKey] integerValue];
  173. NSLog(@"fromType is %zd" , fromType);
  174. /// 切换根控制器
  175. [self.services resetRootViewModel:[self rq_createInitialViewModelWithFromType:fromType]];
  176. /// 切换了根控制器,切记需要将指示器 移到window的最前面
  177. #if defined(DEBUG)||defined(_DEBUG)
  178. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  179. #endif
  180. }];
  181. /// 配置H5
  182. // [SBConfigureManager configure];
  183. /// 检查题库版本
  184. [self rq_configureQuestionUpdate];
  185. [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil];
  186. }
  187. #pragma mark - 调试(DEBUG)模式下的工具条
  188. - (void)rq_configDebugModelTools {
  189. /// 打开调试按钮
  190. [RQDebugTouchView sharedInstance];
  191. /// RQ Fixed: 切换了根控制器,切记需要将指示器 移到window的最前面
  192. [self.window bringSubviewToFront:[RQDebugTouchView sharedInstance]];
  193. }
  194. #pragma mark - 创建根控制器
  195. - (RQBaseViewModel *)rq_createInitialViewModelWithFromType:(RQSwitchRootViewControllerFromType)fromType {
  196. // The user has logged-in.
  197. NSString *version = [[NSUserDefaults standardUserDefaults] valueForKey:RQApplicationVersionKey];
  198. /// 版本不一样就先走 新特性界面
  199. if (![version isEqualToString:RQ_APP_VERSION]) {
  200. return [[RQNewFeatureViewModel alloc] initWithServices:self.services params:@{RQViewCommonValueKey : @"2022.05.13appƬͷ_x264"}];
  201. } else {
  202. switch (fromType) {
  203. case RQSwitchRootViewControllerFromTypeCancelLogin:
  204. return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  205. default: {
  206. /// 这里判断一下
  207. // if (RQStringIsEmpty(RQ_YDTQuestion_Module.car_type)) {
  208. // return [[RQChooseExLibViewModel alloc] initWithServices:self.services params:@{RQViewCommonValueKey : @(YES)}];
  209. // } else {
  210. return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  211. // if ([SAMKeychain rawLogin] && RQ_USER_MANAGER.currentUser) {
  212. // /// 有账号+有用户数据
  213. // /// 已经登录,跳转到主页
  214. // return [[RQMainTabBarViewModel alloc] initWithServices:self.services params:nil];
  215. // } else if(RQ_USER_MANAGER.currentUser) {
  216. // /// 没账号+有用户数据
  217. // /// 跳转到账户登录页面
  218. // return [[RQLoginViewModel alloc] initWithServices:self.services params:nil];
  219. // } else {
  220. // /// 第一次使用
  221. // return [[RQLoginViewModel alloc] initWithServices:self.services params:nil];
  222. // }
  223. // }
  224. }
  225. }
  226. }
  227. }
  228. @end