AppDelegate.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. //
  2. // AppDelegate.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/4.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ViewController.h"
  10. #import <AMapFoundationKit/AMapFoundationKit.h>
  11. #import <AlipaySDK/AlipaySDK.h>
  12. #import "YQAnmationResourceMag.h"
  13. #import "XYLoginViewController.h"
  14. #import "XYAppStorePayHelpler.h"
  15. #import <Bugly/Bugly.h>
  16. #import "StartFigureViewController.h"
  17. #import "XYCoinTypeNameModel.h"
  18. #import "IanAdsStartView.h"
  19. #import "XYBannerListModel.h"
  20. #import <UMCommon/UMCommon.h>
  21. #import "XYCertificationSkillModel.h"
  22. #import "XYSetupUserInfoViewController.h"
  23. #import "XYChatRoomPKTimeModel.h"
  24. #import "XYAPIRiskControManager.h"
  25. #import "StartAgreementManager.h"
  26. //#ifdef DEBUG
  27. //#import <DoraemonKit/DoraemonManager.h>
  28. //#endif
  29. @interface AppDelegate ()
  30. @property (nonatomic, strong) NSDictionary *launchOptions;
  31. @property (nonatomic, strong) StartFigureViewController *startController;
  32. @end
  33. @implementation AppDelegate
  34. #pragma mark - 获取appdelegate
  35. + (AppDelegate *)sharedDelegate {
  36. return (AppDelegate *)[[UIApplication sharedApplication] delegate];
  37. }
  38. //- (void)handleCrashException:(NSString*)exceptionMessage exceptionCategory:(JJExceptionGuardCategory)exceptionCategory extraInfo:(nullable NSDictionary*)info{
  39. // NSLog(@"exceptionMessage=%@ exceptionCategory=%d info=%@",exceptionMessage,exceptionCategory,info);
  40. // NSError *error= [NSError errorWithDomain:exceptionMessage code:exceptionCategory userInfo:info];
  41. // [Bugly reportError:error];
  42. //}
  43. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  44. _launchOptions = launchOptions;
  45. // Override point for customization after application launch.
  46. // [JJException configExceptionCategory:JJExceptionGuardAll];
  47. // [JJException startGuardException];
  48. // [JJException registerExceptionHandle:self];
  49. // #ifdef DEBUG
  50. // [[DoraemonManager shareInstance] installWithPid:@"0c6ffc9f801b2dda5c5fbc508da1688a"];//productId为在“平台端操作指南”中申请的产品id
  51. // #endif
  52. NSLog(@"屏幕高宽:%@", NSStringFromCGSize([UIScreen mainScreen].bounds.size));
  53. // 环境配置
  54. [ZYLService currentService];
  55. // 获取渠道信息
  56. [XYChannelInfoManager sharedInstance];
  57. // 用户信息初始化
  58. [XYUserInfoManager sharedInstance];
  59. if ([APP_Channel_Id isEqualToString:@"21"] || [APP_Channel_Id isEqualToString:@"275963954855936"]) {
  60. /// 苹果市场默认审核中
  61. self.isVersionStatus = YES;
  62. }else {
  63. self.isVersionStatus = NO;
  64. }
  65. // 检查配置 不合格会抛出异常
  66. [self checkConfiguration];
  67. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  68. self.window.backgroundColor = [UIColor clearColor];
  69. self.startController = StartFigureViewController.new;
  70. // 设置自 启动页
  71. [self.window setRootViewController:[[BaseNavigationController alloc] initWithRootViewController:self.startController]];
  72. [self.window makeKeyAndVisible];
  73. //启动页停留0.5秒钟。 防止闪屏
  74. [NSThread sleepForTimeInterval:0.5];
  75. //为了在启动页面不显示statusBar,所以在工程设置里面把statusBar隐藏了,在启动页面过后,显示statusBar。
  76. application.statusBarHidden = NO;
  77. // 修复iOS12.1出现的tabbar偏移的问题
  78. [[UITabBar appearance] setTranslucent:NO];
  79. // 从 iOS 15 开始,TableView 增加sectionHeaderTopPadding属性,默认情况sectionHeaderTopPadding会有22个像素的高度,及默认情况,TableView section header增加22像素的高度
  80. if (@available(iOS 15, *)) {
  81. [UITableView appearance].sectionHeaderTopPadding = 0;
  82. }
  83. WeakSelf
  84. [self.startController setVideoPlaybackCompleted:^{
  85. [weakSelf checkAgreement:application didFinishLaunchingWithOptions:launchOptions];
  86. }];
  87. // 初始化UI之前配置
  88. // 因为第三方key都是接口提供 则需要请求完接口在进行初始化第三方库
  89. //[self init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions];
  90. return YES;
  91. }
  92. - (void)checkAgreement:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  93. // 检查开始协议同意情况
  94. if ([StartAgreementManager checkStartAgreement]) {
  95. //1.获取网络权限 根绝权限进行人机交互
  96. [self addReachabilityManager:application didFinishLaunchingWithOptions:launchOptions];
  97. }else {
  98. [StartAgreementManager showStartAgreementWithController:self.startController callback:^{
  99. //1.获取网络权限 根绝权限进行人机交互
  100. [self addReachabilityManager:application didFinishLaunchingWithOptions:launchOptions];
  101. }];
  102. }
  103. }
  104. /**
  105. 实时检查当前网络状态
  106. */
  107. - (void)addReachabilityManager:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  108. //初始化af网络状态
  109. [ZYLAPPContext sharedInstance];
  110. if (launchOptions) {
  111. [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  112. }else {
  113. //这个可以放在需要侦听的页面
  114. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afNetworkStatusChanged:) name:AFNetworkingReachabilityDidChangeNotification object:launchOptions];
  115. }
  116. }
  117. - (void)afNetworkStatusChanged:(NSNotification *)info {
  118. AFNetworkReachabilityStatus status = [[ZYLAPPContext sharedInstance] currentNetworkStatus];
  119. switch (status) {
  120. case AFNetworkReachabilityStatusNotReachable:{
  121. NSLog(@"网络不通:%@",@(status));
  122. [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  123. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  124. UIAlertController *al = [BlockAlertController alertWithTitle:kLocalizedString(@"不能连接网络") message:kLocalizedString(@"1、请检查当前网络是否畅通。\n2、请检查iPhone设置中此App下无线数据是否已开启。") cancelTitle:kLocalizedString(@"取消") sureTitle:kLocalizedString(@"设置") clickAction:^(UIAlertAction *action) {
  125. if ([action.title isEqualToString:@"设置"]) {
  126. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  127. }
  128. }];
  129. [self.getCurrentController presentViewController:al animated:YES completion:nil];
  130. });
  131. break;
  132. }
  133. case AFNetworkReachabilityStatusReachableViaWiFi:{
  134. NSLog(@"网络通过WIFI连接:%@",@(status));
  135. //2.这个判断主要是防止APP运行中切换网络
  136. [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  137. break;
  138. }
  139. case AFNetworkReachabilityStatusReachableViaWWAN:{
  140. NSLog(@"网络通过无线连接:%@",@(status));
  141. //2.这个判断主要是防止APP运行中切换网络
  142. [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  143. break;
  144. }
  145. default:
  146. break;
  147. }
  148. }
  149. /**
  150. 获取初始信息和离线推送信息
  151. @param application application
  152. @param launchOptions launchOptions
  153. */
  154. - (void)getInitData_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  155. /// 获取本地保存的配置信息
  156. NSDictionary *dict = [YLUserDefault objectForKey:APP_CONFIG_INFO_USERDEFAULT];
  157. if (!ObjectIsNil(dict) && [dict isKindOfClass:[NSDictionary class]]) {
  158. XYAppConfigModel *model = [XYAppConfigModel new];
  159. [model yy_modelSetWithDictionary:dict];
  160. self.appConfigModel = model;
  161. self.isVersionStatus = self.appConfigModel.channelConfig.marketStatus;
  162. }
  163. // 获取APP配置文件
  164. WeakSelf
  165. [[XYConfigAPIManager new] getAppInitConfSuccessHandler:^(ZYLResponseModel *responseModel) {
  166. if (responseModel.codeState) {
  167. XYAppConfigModel *model = [XYAppConfigModel new];
  168. [model yy_modelSetWithDictionary:responseModel.data];
  169. weakSelf.appConfigModel = model;
  170. // 缓存本地
  171. [YLUserDefault setObject:responseModel.data forKey:APP_CONFIG_INFO_USERDEFAULT];
  172. }
  173. weakSelf.isVersionStatus = weakSelf.appConfigModel.channelConfig.marketStatus;
  174. if (weakSelf.isVersionStatus) {
  175. // 审核状态则陪玩不启用
  176. [XYChannelInfoManager sharedInstance].peiWanEnable = NO;
  177. }
  178. // 设置主控制器
  179. self.tabbarVC = [XYMainTabBarViewController new];
  180. [self.window setRootViewController:self.tabbarVC];
  181. //[self.window setRootViewController:[XYSetupUserInfoViewController new]];
  182. [self.window makeKeyAndVisible];
  183. NSDictionary *bannerDict = [LocalFileManage getuserDefaultsWithKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"];
  184. if (bannerDict) {
  185. XYBannerListModel *bannerModel = XYBannerListModel.new;
  186. [bannerModel yy_modelSetWithDictionary:bannerDict];
  187. IanAdsStartView *startView = [IanAdsStartView startAdsViewWithBgImageUrl:bannerModel.bannerPic withClickImageAction:^{
  188. NSLog(@"触发广告,执行事件");
  189. [XYBannerListModel bannerClickHandleWithModel:bannerModel];
  190. }];
  191. [startView startAnimationTime:3 WithCompletionBlock:^(IanAdsStartView *startView){
  192. NSLog(@"广告结束后,执行事件");
  193. }];
  194. }
  195. if (weakSelf.appConfigModel) {
  196. // 初始化第三方
  197. [weakSelf init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions];
  198. }
  199. [self getAppConfigInfoApplication:application didFinishLaunchingWithOptions:launchOptions];
  200. // 取消配置文件请求的网络监听 因为已经请求成功
  201. [NotificationCenter removeObserver:self name:AFNetworkingReachabilityDidChangeNotification object:nil];
  202. } failureHandler:^(NSError *error) {
  203. if (weakSelf.appConfigModel) {
  204. // 初始化第三方
  205. [weakSelf init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions];
  206. }
  207. // 设置主控制器
  208. self.tabbarVC = [XYMainTabBarViewController new];
  209. [self.window setRootViewController:self.tabbarVC];
  210. [self.window makeKeyAndVisible];
  211. [self getAppConfigInfoApplication:application didFinishLaunchingWithOptions:launchOptions];
  212. }];
  213. }
  214. - (void)getAppConfigInfoApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  215. [[YQAnmationResourceMag sharedInstance] downloadResource];
  216. [[XYLiveManger shareInstance] stopAnchorLiveRoom];
  217. if ([XYUserInfoManager nowUser]) {
  218. [[YQAnmationResourceMag sharedInstance] bagGetGiftList];
  219. }
  220. /// 获取APP配置文件 个人信息 版本更新信息
  221. if ([XYUserInfoManager nowUser]) {
  222. // 检查是否存在已支付但没有校验的苹果支付订单
  223. [XYAppStorePayHelpler checkAppStorePaySuccessNoValidationOrders];
  224. // 刷新RTCtoken
  225. [[XYUserAPIManager new] getRtmTokenSuccessHandler:^(ZYLResponseModel *responseModel) {
  226. //登录信息获取
  227. [self loginHandleSuccess:^(BOOL success) {
  228. }];
  229. } failureHandler:^(ZYLNetworkError *error) {
  230. }];
  231. }
  232. // 获取陪陪技能
  233. [[XYConfigAPIManager new] getSkillsSuccessHandler:^(ZYLResponseModel *responseModel) {
  234. NSMutableArray *temp = [NSMutableArray array];
  235. for (NSDictionary *dict in responseModel.data[@"list"]) {
  236. XYCertificationSkillModel *model = XYCertificationSkillModel.new;
  237. [model yy_modelSetWithDictionary:dict];
  238. [temp addObject:model];
  239. }
  240. self.appConfigModel.skills = [temp copy];
  241. } failureHandler:^(ZYLNetworkError *error) {
  242. }];
  243. [[XYConfigAPIManager new] getCoinTypeNameMapSuccessHandler:^(ZYLResponseModel *responseModel) {
  244. NSMutableArray *temp = [NSMutableArray array];
  245. for (NSString *key in responseModel.data.allKeys) {
  246. XYCoinTypeNameModel *model = XYCoinTypeNameModel.new;
  247. model.type = [key integerValue];
  248. model.typeName = responseModel.data[key];
  249. if (model.type == Wallet_Type_Star_Diamond) {
  250. model.typeName = kLocalizedString(@"钻石");
  251. }
  252. if (model.type == Wallet_Type_Star_Dust) {
  253. model.typeName = kLocalizedString(@"粉钻");
  254. }
  255. [temp addObject:model];
  256. }
  257. self.appConfigModel.coinTypeArray = [temp copy];
  258. } failureHandler:^(ZYLNetworkError *error) {
  259. }];
  260. /// 获取开屏广告
  261. [[XYConfigAPIManager new] getOpenScreenBannersSuccessHandler:^(ZYLResponseModel *responseModel) {
  262. NSArray *list = responseModel.data[@"list"];
  263. NSDictionary *bannerDict = [list firstObject];
  264. if (bannerDict) {
  265. [LocalFileManage setUserDefaultsWithObject:bannerDict forKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"];
  266. [IanAdsStartView downloadStartImage:bannerDict[@"bannerPic"]];
  267. }else {
  268. [LocalFileManage setUserDefaultsWithObject:nil forKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"];
  269. }
  270. } failureHandler:^(ZYLNetworkError *error) {
  271. }];
  272. // 获取房间pk配置
  273. [[XYConfigAPIManager new] getBattleRoomInConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
  274. NSMutableArray *temp = [NSMutableArray array];
  275. for (NSDictionary *dict in responseModel.data[@"list"]) {
  276. XYChatRoomPKTimeModel *model = XYChatRoomPKTimeModel.new;
  277. [model yy_modelSetWithDictionary:dict];
  278. [temp addObject:model];
  279. }
  280. self.appConfigModel.battleTimeConfigArray = temp;
  281. } failureHandler:^(ZYLNetworkError *error) {
  282. }];
  283. }
  284. /// 版本更新
  285. - (void)checkVersionUpdates:(BOOL)show {
  286. // appstore市场则不需要显示更新提示
  287. if (self.isVersionStatus) {
  288. return;
  289. }
  290. // 检查版本更新
  291. [[XYConfigAPIManager new] getAppVersionNewWithVersionNum:[APP_BUILD longLongValue] successHandler:^(ZYLResponseModel *responseModel) {
  292. /// data是nil则说明不需要更新
  293. if (!ObjectIsNil(responseModel.result[@"data"])) {
  294. // 这个版本在审核中则不需要弹出版本更新
  295. BOOL marketStatus = [responseModel.data[@"marketStatus"] integerValue];
  296. if (marketStatus) {
  297. // 审核中
  298. return;
  299. }
  300. UIAlertController *al = [UIAlertController alertControllerWithTitle:kLocalizedString(@"版本更新") message:responseModel.result[@"data"][@"versionRemarks"] preferredStyle:UIAlertControllerStyleAlert];
  301. UIView *subView1 = al.view.subviews[0];
  302. UIView *subView2 = subView1.subviews[0];
  303. UIView *subView3 = subView2.subviews[0];
  304. UIView *subView4 = subView3.subviews[0];
  305. UIView *subView5 = subView4.subviews[0];
  306. //取title和message:
  307. UILabel *message12 = subView5.subviews[1];
  308. UILabel *message11 = subView5.subviews[2];
  309. if ([message11 isKindOfClass:[UILabel class]]) {
  310. message11.textAlignment = NSTextAlignmentLeft;
  311. }else {
  312. message12.textAlignment = NSTextAlignmentLeft;
  313. }
  314. UIAlertAction *sure = [UIAlertAction actionWithTitle:kLocalizedString(@"立即更新") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  315. //正式跳转App Store更新
  316. NSURL *url = [NSURL URLWithString:responseModel.result[@"data"][@"versionDownloadUrl"]];
  317. [[UIApplication sharedApplication]openURL:url];
  318. [[self getCurrentController] presentViewController:al animated:YES completion:nil];
  319. }];
  320. [al addAction:sure];
  321. /// versionIsForce:0是选更 1是强更
  322. NSInteger versionIsForce = [responseModel.result[@"data"][@"versionIsForce"] integerValue];
  323. if (versionIsForce == 0) {
  324. UIAlertAction *cancel = [UIAlertAction actionWithTitle:kLocalizedString(@"稍后更新") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  325. }];
  326. [al addAction:cancel];
  327. }
  328. [[self getCurrentController] presentViewController:al animated:YES completion:nil];
  329. }else {
  330. if (show) {
  331. [SVProgressHUD showInfoWithStatus:@"当前已是最新版本"];
  332. }
  333. }
  334. } failureHandler:^(ZYLNetworkError *error) {
  335. }];
  336. }
  337. /**
  338. 配置一些初始设置和第三方库初始化
  339. @param application application
  340. @param launchOptions launchOptions
  341. */
  342. - (void)init_thirdPartyApplication:(UIApplication *)application initialParamsBeforInitUI:(NSDictionary *)launchOptions {
  343. //第三方库的初始化
  344. // [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
  345. // [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  346. // [SVProgressHUD setBackgroundColor:ColorFromHexString(@"#362F2D")];
  347. // [SVProgressHUD setMinimumDismissTimeInterval:1];
  348. // [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
  349. // [SVProgressHUD setMinimumSize:CGSizeMake(120.0f, 60.0f)];
  350. // [SVProgressHUD setFont:Font_B(16)];
  351. // [SVProgressHUD setCornerRadius:8];
  352. [SVProgressHUD setBackgroundColor:ColorFromHexStringWithAlpha(@"#362F2D", 0.3)];
  353. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
  354. [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
  355. [SVProgressHUD setMinimumDismissTimeInterval:0.7];
  356. [SVProgressHUD setMaximumDismissTimeInterval:5.0];
  357. [SVProgressHUD setCornerRadius:14];
  358. // [SVProgressHUD setErrorImage:nil];
  359. // [SVProgressHUD setInfoImage:nil];
  360. // [SVProgressHUD setImageViewSize:CGSizeZero];
  361. [SVProgressHUD setInfoImage:nil];
  362. // _backgroundColor = [UIColor whiteColor];
  363. // _foregroundColor = [UIColor blackColor];
  364. // _backgroundLayerColor = [UIColor colorWithWhite:0 alpha:0.4];
  365. // 高德地图
  366. [AMapServices sharedServices].apiKey = [XYChannelInfoManager sharedInstance].location_Key;
  367. /// 单次定位
  368. [[LocationManage sharedInstance] startSingleLocation];
  369. /// 闪验一键登录初始化
  370. [self cl_application:application didFinishLaunchingWithOptions:launchOptions];
  371. /// 微信 SDK初始化
  372. [XYSocialRegisterHandler wechatRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login] Link:[XYChannelInfoManager sharedInstance].callbackUrl];
  373. /// QQ SDK初始化
  374. [XYSocialRegisterHandler qqRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login]];
  375. /// 微博 SDK初始化
  376. [XYSocialRegisterHandler sinaRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login]];
  377. // 注册推送 修改为登录APP账号后获取通知权限:
  378. //[self registerAPNS:application];
  379. /// 阿里推送初始化
  380. [self push_application:application didFinishLaunchingWithOptions:launchOptions];
  381. /// 融云IM 初始化
  382. [[XYIMBaseManager sharedInstance] im_setupAppId:[XYChannelInfoManager sharedInstance].rcAppId];
  383. /// 友盟初始化
  384. if ([ZYLService currentService].environment == ZYLServiceEnvironmentRelease) {
  385. [StatisticsManager UM_registeredWithAppkey:[XYChannelInfoManager sharedInstance].UMAppkey channel:[NSString stringWithFormat:@"%@",APP_Channel_Id]];
  386. }
  387. // 反欺诈风控(数美)
  388. [XYAPIRiskControManager initSdkWithOrganization:[XYChannelInfoManager sharedInstance].shumeiOrganization appId:[XYChannelInfoManager sharedInstance].shumeiAppId publicKey:[XYChannelInfoManager sharedInstance].shumeiIosPublicKey];
  389. // bugly初始化
  390. NSString *buglyAppId = @"123b6144e8905";
  391. NSString *buglyChannel = [NSString stringWithFormat:@"%@",APP_Channel_Id];
  392. BuglyConfig *buglyConfig = [[BuglyConfig alloc] init];
  393. buglyConfig.channel = buglyChannel;
  394. [Bugly startWithAppId:buglyAppId config:buglyConfig];
  395. [Bugly setUserIdentifier:@"1000000"];
  396. // 第三方图片浏览框架 相册全下通知
  397. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(photoLimit:) name:@"YBIBImageDataPhotoLimit" object:nil];
  398. }
  399. - (void)photoLimit:(NSNotification *)notification {
  400. UIAlertController *al = [BlockAlertController alertWithTitle:kLocalizedString(@"无法保存至相册") message:kLocalizedString(@"请在iPhone的""设置-隐私-照片""中允许访问照片") cancelTitle:kLocalizedString(@"取消") sureTitle:kLocalizedString(@"设置") clickAction:^(UIAlertAction *action) {
  401. if ([action.title isEqualToString:@"设置"]) {
  402. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  403. }
  404. }];
  405. [self.getCurrentController presentViewController:al animated:YES completion:nil];
  406. }
  407. - (BOOL)isCoolPeriod:(NSDictionary *)dataDict{
  408. BOOL isCoolPeriod = [dataDict[@"isCoolPeriod"] intValue];
  409. if (isCoolPeriod) {
  410. [SVProgressHUD dismiss];
  411. kWEAKSELF
  412. CustomActionAlertController *alertController = [[CustomActionAlertController alloc] initWithTitle:nil message:kLocalizedString(@"当前账号已注销,还未超过180天的注销冷静期,用该账号重新登录会视为放弃注销,是否登录?") sure:kLocalizedString(@"登录") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  413. if ([title isEqualToString:kLocalizedString(@"登录")]) {
  414. [[XYUserAPIManager new] cancelLogout:nil successHandler:^(ZYLResponseModel *responseModel) {
  415. if (weakSelf.XYCoolPeriodAgainLogin) {
  416. weakSelf.XYCoolPeriodAgainLogin(YES);
  417. }
  418. } failureHandler:^(ZYLNetworkError *error) {
  419. [SVProgressHUD dismiss];
  420. [SVProgressHUD showInfoWithStatus:error.domain];
  421. }];
  422. }
  423. }];
  424. [alertController show];
  425. }
  426. return isCoolPeriod;
  427. }
  428. #pragma mark — Public
  429. /// 获取当前显示的控制器
  430. - (UIViewController *)getCurrentController {
  431. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  432. UIViewController *appRootVC = window.rootViewController;
  433. UIViewController *topVC = appRootVC;
  434. if (topVC.presentedViewController) {
  435. topVC = topVC.presentedViewController;
  436. if ([topVC isKindOfClass:[UINavigationController class]]) {
  437. UINavigationController *rootNav = (UINavigationController *)topVC;
  438. return rootNav.topViewController;
  439. }else {
  440. return topVC;
  441. }
  442. }else {
  443. if ([appRootVC isKindOfClass:[XYMainTabBarViewController class]]) {
  444. UINavigationController *nav = self.tabbarVC.tabBarController.selectedViewController;
  445. return nav.topViewController;
  446. }else if ([appRootVC isKindOfClass:[UINavigationController class]]) {
  447. UINavigationController *rootNav = (UINavigationController *)appRootVC;
  448. return rootNav.topViewController;
  449. }else {
  450. return appRootVC;
  451. }
  452. }
  453. }
  454. - (void)dismissViewController:(void(^)(void))completion {
  455. //获取根视图
  456. UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
  457. UIViewController *topVC = appRootVC;
  458. if (topVC.presentedViewController) {
  459. //有么有persentview 有了删除
  460. topVC = topVC.presentedViewController;
  461. [topVC dismissViewControllerAnimated:NO completion:completion];
  462. }else {
  463. if (completion) {
  464. completion();
  465. }
  466. }
  467. }
  468. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  469. if ([url.host isEqualToString:@"safepay"]) {
  470. //跳转支付宝钱包进行支付,处理支付结果
  471. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  472. NSLog(@"result = %@",resultDic);
  473. [NotificationCenter postNotificationName:ALI_APP_PAY_NOTIFICATION object:nil userInfo:resultDic];
  474. }];
  475. }
  476. //这里可以判断是否是社交类url
  477. return [[XYSocialRegisterHandler sharedInstance] application:app openURL:url options:options];
  478. }
  479. - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  480. //这里可以判断是否是社交类url
  481. return [[XYSocialRegisterHandler sharedInstance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
  482. }
  483. #pragma mark — 请求deviceToken回调
  484. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  485. NSString *deviceTokenString = [self getHexStringForData:deviceToken];
  486. NSLog(@"deviceToken 获取成功:%@", deviceTokenString);
  487. self.deviceToken = deviceToken;
  488. [self push_application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  489. }
  490. /// deviceToken转字符串
  491. - (NSString *)getHexStringForData:(NSData *)data {
  492. NSUInteger len = [data length];
  493. char *chars = (char *)[data bytes];
  494. NSMutableString *hexString = [[NSMutableString alloc] init];
  495. for (NSUInteger i = 0; i < len; i++) {
  496. [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]];
  497. }
  498. return hexString;
  499. }
  500. /// 检查配置 不合格会抛出异常
  501. - (void)checkConfiguration {
  502. // 检查build长度 不合格会抛出气场
  503. NSString *build = APP_BUILD;
  504. if (build.length != 10) {
  505. @throw [NSException exceptionWithName:@"build效验" reason:@"build不满足10位长度规范" userInfo:nil];
  506. }
  507. }
  508. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  509. NSLog(@"deviceToken 获取失败:%@", error);
  510. }
  511. - (void)applicationWillResignActive:(UIApplication *)application {
  512. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  513. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  514. if ([XYLiveManger shareInstance].AppBackBackgroundBlock) {
  515. [XYLiveManger shareInstance].AppBackBackgroundBlock(YES);
  516. }
  517. if ([XYLiveManger shareInstance].AppBackBackgroundBlock1) {
  518. [XYLiveManger shareInstance].AppBackBackgroundBlock1(YES);
  519. }
  520. if ([XYLiveManger shareInstance].AppBackBackgroundBlock2) {
  521. [XYLiveManger shareInstance].AppBackBackgroundBlock2(YES);
  522. }
  523. [NotificationCenter postNotificationName:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil];
  524. }
  525. - (void)applicationDidEnterBackground:(UIApplication *)application {
  526. [UIApplication sharedApplication].applicationIconBadgeNumber = [XYIMUnReadCountManager sharedInstance].currentUnreadCount;
  527. }
  528. - (void)applicationWillEnterForeground:(UIApplication *)application {
  529. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  530. }
  531. - (void)applicationDidBecomeActive:(UIApplication *)application {
  532. if ([XYLiveManger shareInstance].AppBackBackgroundBlock) {
  533. [XYLiveManger shareInstance].AppBackBackgroundBlock(NO);
  534. }
  535. if ([XYLiveManger shareInstance].AppBackBackgroundBlock1) {
  536. [XYLiveManger shareInstance].AppBackBackgroundBlock1(NO);
  537. }
  538. if ([XYLiveManger shareInstance].AppBackBackgroundBlock2) {
  539. [XYLiveManger shareInstance].AppBackBackgroundBlock2(NO);
  540. }
  541. [SVProgressHUD dismiss];
  542. [NotificationCenter postNotificationName:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil];
  543. }
  544. - (void)applicationWillTerminate:(UIApplication *)application {
  545. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  546. }
  547. @end