AppDelegate.m 10 KB

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