AppDelegate.m 9.7 KB

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