// // AppDelegate.m // Starbuds // // Created by 翟玉磊 on 2019/12/4. // Copyright © 2019 翟玉磊. All rights reserved. // #import "AppDelegate.h" #import "ViewController.h" #import #import #import "YQAnmationResourceMag.h" #import "XYLoginViewController.h" #import "XYAppStorePayHelpler.h" #import #import "StartFigureViewController.h" #import "XYCoinTypeNameModel.h" #import "IanAdsStartView.h" #import "XYBannerListModel.h" #import #import "XYCertificationSkillModel.h" #import "XYSetupUserInfoViewController.h" #import "XYChatRoomPKTimeModel.h" #import "XYAPIRiskControManager.h" #import "StartAgreementManager.h" //#ifdef DEBUG //#import //#endif @interface AppDelegate () @property (nonatomic, strong) NSDictionary *launchOptions; @property (nonatomic, strong) StartFigureViewController *startController; @end @implementation AppDelegate #pragma mark - 获取appdelegate + (AppDelegate *)sharedDelegate { return (AppDelegate *)[[UIApplication sharedApplication] delegate]; } //- (void)handleCrashException:(NSString*)exceptionMessage exceptionCategory:(JJExceptionGuardCategory)exceptionCategory extraInfo:(nullable NSDictionary*)info{ // NSLog(@"exceptionMessage=%@ exceptionCategory=%d info=%@",exceptionMessage,exceptionCategory,info); // NSError *error= [NSError errorWithDomain:exceptionMessage code:exceptionCategory userInfo:info]; // [Bugly reportError:error]; //} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _launchOptions = launchOptions; // Override point for customization after application launch. // [JJException configExceptionCategory:JJExceptionGuardAll]; // [JJException startGuardException]; // [JJException registerExceptionHandle:self]; // #ifdef DEBUG // [[DoraemonManager shareInstance] installWithPid:@"0c6ffc9f801b2dda5c5fbc508da1688a"];//productId为在“平台端操作指南”中申请的产品id // #endif NSLog(@"屏幕高宽:%@", NSStringFromCGSize([UIScreen mainScreen].bounds.size)); // 环境配置 [ZYLService currentService]; // 获取渠道信息 [XYChannelInfoManager sharedInstance]; // 用户信息初始化 [XYUserInfoManager sharedInstance]; if ([APP_Channel_Id isEqualToString:@"21"] || [APP_Channel_Id isEqualToString:@"275963954855936"]) { /// 苹果市场默认审核中 self.isVersionStatus = YES; }else { self.isVersionStatus = NO; } // 检查配置 不合格会抛出异常 [self checkConfiguration]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor clearColor]; self.startController = StartFigureViewController.new; // 设置自 启动页 [self.window setRootViewController:[[BaseNavigationController alloc] initWithRootViewController:self.startController]]; [self.window makeKeyAndVisible]; //启动页停留0.5秒钟。 防止闪屏 [NSThread sleepForTimeInterval:0.5]; //为了在启动页面不显示statusBar,所以在工程设置里面把statusBar隐藏了,在启动页面过后,显示statusBar。 application.statusBarHidden = NO; // 修复iOS12.1出现的tabbar偏移的问题 [[UITabBar appearance] setTranslucent:NO]; // 从 iOS 15 开始,TableView 增加sectionHeaderTopPadding属性,默认情况sectionHeaderTopPadding会有22个像素的高度,及默认情况,TableView section header增加22像素的高度 if (@available(iOS 15, *)) { [UITableView appearance].sectionHeaderTopPadding = 0; } WeakSelf [self.startController setVideoPlaybackCompleted:^{ [weakSelf checkAgreement:application didFinishLaunchingWithOptions:launchOptions]; }]; // 初始化UI之前配置 // 因为第三方key都是接口提供 则需要请求完接口在进行初始化第三方库 //[self init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions]; return YES; } - (void)checkAgreement:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 检查开始协议同意情况 if ([StartAgreementManager checkStartAgreement]) { //1.获取网络权限 根绝权限进行人机交互 [self addReachabilityManager:application didFinishLaunchingWithOptions:launchOptions]; }else { [StartAgreementManager showStartAgreementWithController:self.startController callback:^{ //1.获取网络权限 根绝权限进行人机交互 [self addReachabilityManager:application didFinishLaunchingWithOptions:launchOptions]; }]; } } /** 实时检查当前网络状态 */ - (void)addReachabilityManager:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //初始化af网络状态 [ZYLAPPContext sharedInstance]; if (launchOptions) { [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions]; }else { //这个可以放在需要侦听的页面 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afNetworkStatusChanged:) name:AFNetworkingReachabilityDidChangeNotification object:launchOptions]; } } - (void)afNetworkStatusChanged:(NSNotification *)info { AFNetworkReachabilityStatus status = [[ZYLAPPContext sharedInstance] currentNetworkStatus]; switch (status) { case AFNetworkReachabilityStatusNotReachable:{ NSLog(@"网络不通:%@",@(status)); [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertController *al = [BlockAlertController alertWithTitle:kLocalizedString(@"不能连接网络") message:kLocalizedString(@"1、请检查当前网络是否畅通。\n2、请检查iPhone设置中此App下无线数据是否已开启。") cancelTitle:kLocalizedString(@"取消") sureTitle:kLocalizedString(@"设置") clickAction:^(UIAlertAction *action) { if ([action.title isEqualToString:@"设置"]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } }]; [self.getCurrentController presentViewController:al animated:YES completion:nil]; }); break; } case AFNetworkReachabilityStatusReachableViaWiFi:{ NSLog(@"网络通过WIFI连接:%@",@(status)); //2.这个判断主要是防止APP运行中切换网络 [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions]; break; } case AFNetworkReachabilityStatusReachableViaWWAN:{ NSLog(@"网络通过无线连接:%@",@(status)); //2.这个判断主要是防止APP运行中切换网络 [self getInitData_application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions]; break; } default: break; } } /** 获取初始信息和离线推送信息 @param application application @param launchOptions launchOptions */ - (void)getInitData_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /// 获取本地保存的配置信息 NSDictionary *dict = [YLUserDefault objectForKey:APP_CONFIG_INFO_USERDEFAULT]; if (!ObjectIsNil(dict) && [dict isKindOfClass:[NSDictionary class]]) { XYAppConfigModel *model = [XYAppConfigModel new]; [model yy_modelSetWithDictionary:dict]; self.appConfigModel = model; self.isVersionStatus = self.appConfigModel.channelConfig.marketStatus; } // 获取APP配置文件 WeakSelf [[XYConfigAPIManager new] getAppInitConfSuccessHandler:^(ZYLResponseModel *responseModel) { if (responseModel.codeState) { XYAppConfigModel *model = [XYAppConfigModel new]; [model yy_modelSetWithDictionary:responseModel.data]; weakSelf.appConfigModel = model; // 缓存本地 [YLUserDefault setObject:responseModel.data forKey:APP_CONFIG_INFO_USERDEFAULT]; } weakSelf.isVersionStatus = weakSelf.appConfigModel.channelConfig.marketStatus; if (weakSelf.isVersionStatus) { // 审核状态则陪玩不启用 [XYChannelInfoManager sharedInstance].peiWanEnable = NO; } // 设置主控制器 self.tabbarVC = [XYMainTabBarViewController new]; [self.window setRootViewController:self.tabbarVC]; //[self.window setRootViewController:[XYSetupUserInfoViewController new]]; [self.window makeKeyAndVisible]; NSDictionary *bannerDict = [LocalFileManage getuserDefaultsWithKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"]; if (bannerDict) { XYBannerListModel *bannerModel = XYBannerListModel.new; [bannerModel yy_modelSetWithDictionary:bannerDict]; IanAdsStartView *startView = [IanAdsStartView startAdsViewWithBgImageUrl:bannerModel.bannerPic withClickImageAction:^{ NSLog(@"触发广告,执行事件"); [XYBannerListModel bannerClickHandleWithModel:bannerModel]; }]; [startView startAnimationTime:3 WithCompletionBlock:^(IanAdsStartView *startView){ NSLog(@"广告结束后,执行事件"); }]; } if (weakSelf.appConfigModel) { // 初始化第三方 [weakSelf init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions]; } [self getAppConfigInfoApplication:application didFinishLaunchingWithOptions:launchOptions]; // 取消配置文件请求的网络监听 因为已经请求成功 [NotificationCenter removeObserver:self name:AFNetworkingReachabilityDidChangeNotification object:nil]; } failureHandler:^(NSError *error) { if (weakSelf.appConfigModel) { // 初始化第三方 [weakSelf init_thirdPartyApplication:application initialParamsBeforInitUI:launchOptions]; } // 设置主控制器 self.tabbarVC = [XYMainTabBarViewController new]; [self.window setRootViewController:self.tabbarVC]; [self.window makeKeyAndVisible]; [self getAppConfigInfoApplication:application didFinishLaunchingWithOptions:launchOptions]; }]; } - (void)getAppConfigInfoApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[YQAnmationResourceMag sharedInstance] downloadResource]; [[XYLiveManger shareInstance] stopAnchorLiveRoom]; if ([XYUserInfoManager nowUser]) { [[YQAnmationResourceMag sharedInstance] bagGetGiftList]; } /// 获取APP配置文件 个人信息 版本更新信息 if ([XYUserInfoManager nowUser]) { // 检查是否存在已支付但没有校验的苹果支付订单 [XYAppStorePayHelpler checkAppStorePaySuccessNoValidationOrders]; // 刷新RTCtoken [[XYUserAPIManager new] getRtmTokenSuccessHandler:^(ZYLResponseModel *responseModel) { //登录信息获取 [self loginHandleSuccess:^(BOOL success) { }]; } failureHandler:^(ZYLNetworkError *error) { }]; } // 获取陪陪技能 [[XYConfigAPIManager new] getSkillsSuccessHandler:^(ZYLResponseModel *responseModel) { NSMutableArray *temp = [NSMutableArray array]; for (NSDictionary *dict in responseModel.data[@"list"]) { XYCertificationSkillModel *model = XYCertificationSkillModel.new; [model yy_modelSetWithDictionary:dict]; [temp addObject:model]; } self.appConfigModel.skills = [temp copy]; } failureHandler:^(ZYLNetworkError *error) { }]; [[XYConfigAPIManager new] getCoinTypeNameMapSuccessHandler:^(ZYLResponseModel *responseModel) { NSMutableArray *temp = [NSMutableArray array]; for (NSString *key in responseModel.data.allKeys) { XYCoinTypeNameModel *model = XYCoinTypeNameModel.new; model.type = [key integerValue]; model.typeName = responseModel.data[key]; if (model.type == Wallet_Type_Star_Diamond) { model.typeName = kLocalizedString(@"钻石"); } if (model.type == Wallet_Type_Star_Dust) { model.typeName = kLocalizedString(@"粉钻"); } [temp addObject:model]; } self.appConfigModel.coinTypeArray = [temp copy]; } failureHandler:^(ZYLNetworkError *error) { }]; /// 获取开屏广告 [[XYConfigAPIManager new] getOpenScreenBannersSuccessHandler:^(ZYLResponseModel *responseModel) { NSArray *list = responseModel.data[@"list"]; NSDictionary *bannerDict = [list firstObject]; if (bannerDict) { [LocalFileManage setUserDefaultsWithObject:bannerDict forKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"]; [IanAdsStartView downloadStartImage:bannerDict[@"bannerPic"]]; }else { [LocalFileManage setUserDefaultsWithObject:nil forKey:@"OPEN_SCREEN_BANNERS_USERDEFAULTS"]; } } failureHandler:^(ZYLNetworkError *error) { }]; // 获取房间pk配置 [[XYConfigAPIManager new] getBattleRoomInConfigSuccessHandler:^(ZYLResponseModel *responseModel) { NSMutableArray *temp = [NSMutableArray array]; for (NSDictionary *dict in responseModel.data[@"list"]) { XYChatRoomPKTimeModel *model = XYChatRoomPKTimeModel.new; [model yy_modelSetWithDictionary:dict]; [temp addObject:model]; } self.appConfigModel.battleTimeConfigArray = temp; } failureHandler:^(ZYLNetworkError *error) { }]; } /// 版本更新 - (void)checkVersionUpdates:(BOOL)show { // appstore市场则不需要显示更新提示 if (self.isVersionStatus) { return; } // 检查版本更新 [[XYConfigAPIManager new] getAppVersionNewWithVersionNum:[APP_BUILD longLongValue] successHandler:^(ZYLResponseModel *responseModel) { /// data是nil则说明不需要更新 if (!ObjectIsNil(responseModel.result[@"data"])) { // 这个版本在审核中则不需要弹出版本更新 BOOL marketStatus = [responseModel.data[@"marketStatus"] integerValue]; if (marketStatus) { // 审核中 return; } UIAlertController *al = [UIAlertController alertControllerWithTitle:kLocalizedString(@"版本更新") message:responseModel.result[@"data"][@"versionRemarks"] preferredStyle:UIAlertControllerStyleAlert]; UIView *subView1 = al.view.subviews[0]; UIView *subView2 = subView1.subviews[0]; UIView *subView3 = subView2.subviews[0]; UIView *subView4 = subView3.subviews[0]; UIView *subView5 = subView4.subviews[0]; //取title和message: UILabel *message12 = subView5.subviews[1]; UILabel *message11 = subView5.subviews[2]; if ([message11 isKindOfClass:[UILabel class]]) { message11.textAlignment = NSTextAlignmentLeft; }else { message12.textAlignment = NSTextAlignmentLeft; } UIAlertAction *sure = [UIAlertAction actionWithTitle:kLocalizedString(@"立即更新") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { //正式跳转App Store更新 NSURL *url = [NSURL URLWithString:responseModel.result[@"data"][@"versionDownloadUrl"]]; [[UIApplication sharedApplication]openURL:url]; [[self getCurrentController] presentViewController:al animated:YES completion:nil]; }]; [al addAction:sure]; /// versionIsForce:0是选更 1是强更 NSInteger versionIsForce = [responseModel.result[@"data"][@"versionIsForce"] integerValue]; if (versionIsForce == 0) { UIAlertAction *cancel = [UIAlertAction actionWithTitle:kLocalizedString(@"稍后更新") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [al addAction:cancel]; } [[self getCurrentController] presentViewController:al animated:YES completion:nil]; }else { if (show) { [SVProgressHUD showInfoWithStatus:@"当前已是最新版本"]; } } } failureHandler:^(ZYLNetworkError *error) { }]; } /** 配置一些初始设置和第三方库初始化 @param application application @param launchOptions launchOptions */ - (void)init_thirdPartyApplication:(UIApplication *)application initialParamsBeforInitUI:(NSDictionary *)launchOptions { //第三方库的初始化 // [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear]; // [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom]; // [SVProgressHUD setBackgroundColor:ColorFromHexString(@"#362F2D")]; // [SVProgressHUD setMinimumDismissTimeInterval:1]; // [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; // [SVProgressHUD setMinimumSize:CGSizeMake(120.0f, 60.0f)]; // [SVProgressHUD setFont:Font_B(16)]; // [SVProgressHUD setCornerRadius:8]; [SVProgressHUD setBackgroundColor:ColorFromHexStringWithAlpha(@"#362F2D", 0.3)]; [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark]; [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear]; [SVProgressHUD setMinimumDismissTimeInterval:0.7]; [SVProgressHUD setMaximumDismissTimeInterval:5.0]; [SVProgressHUD setCornerRadius:14]; // [SVProgressHUD setErrorImage:nil]; // [SVProgressHUD setInfoImage:nil]; // [SVProgressHUD setImageViewSize:CGSizeZero]; [SVProgressHUD setInfoImage:nil]; // _backgroundColor = [UIColor whiteColor]; // _foregroundColor = [UIColor blackColor]; // _backgroundLayerColor = [UIColor colorWithWhite:0 alpha:0.4]; // 高德地图 [AMapServices sharedServices].apiKey = [XYChannelInfoManager sharedInstance].location_Key; /// 单次定位 [[LocationManage sharedInstance] startSingleLocation]; /// 闪验一键登录初始化 [self cl_application:application didFinishLaunchingWithOptions:launchOptions]; /// 微信 SDK初始化 [XYSocialRegisterHandler wechatRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login] Link:[XYChannelInfoManager sharedInstance].callbackUrl]; /// QQ SDK初始化 [XYSocialRegisterHandler qqRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login]]; /// 微博 SDK初始化 [XYSocialRegisterHandler sinaRegister:[XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login]]; // 注册推送 修改为登录APP账号后获取通知权限: //[self registerAPNS:application]; /// 阿里推送初始化 [self push_application:application didFinishLaunchingWithOptions:launchOptions]; /// 融云IM 初始化 [[XYIMBaseManager sharedInstance] im_setupAppId:[XYChannelInfoManager sharedInstance].rcAppId]; /// 友盟初始化 if ([ZYLService currentService].environment == ZYLServiceEnvironmentRelease) { [StatisticsManager UM_registeredWithAppkey:[XYChannelInfoManager sharedInstance].UMAppkey channel:[NSString stringWithFormat:@"%@",APP_Channel_Id]]; } // 反欺诈风控(数美) [XYAPIRiskControManager initSdkWithOrganization:[XYChannelInfoManager sharedInstance].shumeiOrganization appId:[XYChannelInfoManager sharedInstance].shumeiAppId publicKey:[XYChannelInfoManager sharedInstance].shumeiIosPublicKey]; // bugly初始化 NSString *buglyAppId = @"123b6144e8905"; NSString *buglyChannel = [NSString stringWithFormat:@"%@",APP_Channel_Id]; BuglyConfig *buglyConfig = [[BuglyConfig alloc] init]; buglyConfig.channel = buglyChannel; [Bugly startWithAppId:buglyAppId config:buglyConfig]; [Bugly setUserIdentifier:@"1000000"]; // 第三方图片浏览框架 相册全下通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(photoLimit:) name:@"YBIBImageDataPhotoLimit" object:nil]; } - (void)photoLimit:(NSNotification *)notification { UIAlertController *al = [BlockAlertController alertWithTitle:kLocalizedString(@"无法保存至相册") message:kLocalizedString(@"请在iPhone的""设置-隐私-照片""中允许访问照片") cancelTitle:kLocalizedString(@"取消") sureTitle:kLocalizedString(@"设置") clickAction:^(UIAlertAction *action) { if ([action.title isEqualToString:@"设置"]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } }]; [self.getCurrentController presentViewController:al animated:YES completion:nil]; } - (BOOL)isCoolPeriod:(NSDictionary *)dataDict{ BOOL isCoolPeriod = [dataDict[@"isCoolPeriod"] intValue]; if (isCoolPeriod) { [SVProgressHUD dismiss]; kWEAKSELF CustomActionAlertController *alertController = [[CustomActionAlertController alloc] initWithTitle:nil message:kLocalizedString(@"当前账号已注销,还未超过180天的注销冷静期,用该账号重新登录会视为放弃注销,是否登录?") sure:kLocalizedString(@"登录") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) { if ([title isEqualToString:kLocalizedString(@"登录")]) { [[XYUserAPIManager new] cancelLogout:nil successHandler:^(ZYLResponseModel *responseModel) { if (weakSelf.XYCoolPeriodAgainLogin) { weakSelf.XYCoolPeriodAgainLogin(YES); } } failureHandler:^(ZYLNetworkError *error) { [SVProgressHUD dismiss]; [SVProgressHUD showInfoWithStatus:error.domain]; }]; } }]; [alertController show]; } return isCoolPeriod; } #pragma mark — Public /// 获取当前显示的控制器 - (UIViewController *)getCurrentController { UIWindow *window = [UIApplication sharedApplication].keyWindow; UIViewController *appRootVC = window.rootViewController; UIViewController *topVC = appRootVC; if (topVC.presentedViewController) { topVC = topVC.presentedViewController; if ([topVC isKindOfClass:[UINavigationController class]]) { UINavigationController *rootNav = (UINavigationController *)topVC; return rootNav.topViewController; }else { return topVC; } }else { if ([appRootVC isKindOfClass:[XYMainTabBarViewController class]]) { UINavigationController *nav = self.tabbarVC.tabBarController.selectedViewController; return nav.topViewController; }else if ([appRootVC isKindOfClass:[UINavigationController class]]) { UINavigationController *rootNav = (UINavigationController *)appRootVC; return rootNav.topViewController; }else { return appRootVC; } } } - (void)dismissViewController:(void(^)(void))completion { //获取根视图 UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController; UIViewController *topVC = appRootVC; if (topVC.presentedViewController) { //有么有persentview 有了删除 topVC = topVC.presentedViewController; [topVC dismissViewControllerAnimated:NO completion:completion]; }else { if (completion) { completion(); } } } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { if ([url.host isEqualToString:@"safepay"]) { //跳转支付宝钱包进行支付,处理支付结果 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); [NotificationCenter postNotificationName:ALI_APP_PAY_NOTIFICATION object:nil userInfo:resultDic]; }]; } //这里可以判断是否是社交类url return [[XYSocialRegisterHandler sharedInstance] application:app openURL:url options:options]; } - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { //这里可以判断是否是社交类url return [[XYSocialRegisterHandler sharedInstance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; } #pragma mark — 请求deviceToken回调 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *deviceTokenString = [self getHexStringForData:deviceToken]; NSLog(@"deviceToken 获取成功:%@", deviceTokenString); self.deviceToken = deviceToken; [self push_application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } /// deviceToken转字符串 - (NSString *)getHexStringForData:(NSData *)data { NSUInteger len = [data length]; char *chars = (char *)[data bytes]; NSMutableString *hexString = [[NSMutableString alloc] init]; for (NSUInteger i = 0; i < len; i++) { [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]]; } return hexString; } /// 检查配置 不合格会抛出异常 - (void)checkConfiguration { // 检查build长度 不合格会抛出气场 NSString *build = APP_BUILD; if (build.length != 10) { @throw [NSException exceptionWithName:@"build效验" reason:@"build不满足10位长度规范" userInfo:nil]; } } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"deviceToken 获取失败:%@", error); } - (void)applicationWillResignActive:(UIApplication *)application { // 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. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. if ([XYLiveManger shareInstance].AppBackBackgroundBlock) { [XYLiveManger shareInstance].AppBackBackgroundBlock(YES); } if ([XYLiveManger shareInstance].AppBackBackgroundBlock1) { [XYLiveManger shareInstance].AppBackBackgroundBlock1(YES); } if ([XYLiveManger shareInstance].AppBackBackgroundBlock2) { [XYLiveManger shareInstance].AppBackBackgroundBlock2(YES); } [NotificationCenter postNotificationName:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil]; } - (void)applicationDidEnterBackground:(UIApplication *)application { [UIApplication sharedApplication].applicationIconBadgeNumber = [XYIMUnReadCountManager sharedInstance].currentUnreadCount; } - (void)applicationWillEnterForeground:(UIApplication *)application { // 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. } - (void)applicationDidBecomeActive:(UIApplication *)application { if ([XYLiveManger shareInstance].AppBackBackgroundBlock) { [XYLiveManger shareInstance].AppBackBackgroundBlock(NO); } if ([XYLiveManger shareInstance].AppBackBackgroundBlock1) { [XYLiveManger shareInstance].AppBackBackgroundBlock1(NO); } if ([XYLiveManger shareInstance].AppBackBackgroundBlock2) { [XYLiveManger shareInstance].AppBackBackgroundBlock2(NO); } [SVProgressHUD dismiss]; [NotificationCenter postNotificationName:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil]; } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end