AppDelegate.m 10 KB

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