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