AppDelegate.m 11 KB

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