AppDelegate.m 9.9 KB

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