// // APPdelegateModularForSystemSetting.m // jiaPei // // Created by 张嵘 on 2019/3/26. // Copyright © 2019 JCZ. All rights reserved. // #import "APPdelegateModularForSystemSetting.h" #import "RQAppEventAnnotation.h" #import #if defined(__IPHONE_14_0) #import //适配iOS14 #endif RQAppEventMod(APPdelegateModularForSystemSetting) @interface APPdelegateModularForSystemSetting () @property (nonatomic, readwrite, assign) BOOL isShowNetWorkAuth; @property (nonatomic, readwrite, assign) UIBackgroundTaskIdentifier backgroundTaskInvalid; @end @implementation APPdelegateModularForSystemSetting - (NSInteger)moduleLevel { return 0; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self initMudule]; // [self destroyModule]; return YES; } - (void)initMudule { NSString *version = [UIDevice currentDevice].systemVersion; if ([version isEqualToString:@"12.1.0"]) { // 针对 12.1 的iOS系统进行处理 [[UITabBar appearance] setTranslucent:NO]; } if (@available(iOS 15.0, *)) { [UITableView appearance].sectionHeaderTopPadding = 0; } } /// 程序挂起 - (void)applicationWillResignActive:(UIApplication *)application { [EAGLContext setCurrentContext:nil]; } /// 程序进入后台 - (void)applicationDidEnterBackground:(UIApplication *)application { if (!myDelegate.scPeriodVC) { if (myDelegate.timer) { [myDelegate.timer setFireDate:[NSDate distantFuture]]; } }else { if (!myDelegate.scPeriodVC.haveBlueTooth && myDelegate.timer) { [myDelegate.timer setFireDate:[NSDate distantFuture]]; } } myDelegate.isBackgroundTask = YES; [EAGLContext setCurrentContext:nil]; // 实现如下代码,才能使程序处于后台时被杀死,调用applicationWillTerminate:方法 [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(){}]; } /// 应用处于后台,所有下载任务完成调用 - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.backgroundSessionCompletionHandler = completionHandler; } /// 程序意外退出 - (void)applicationWillTerminate:(UIApplication *)application { //NSLog(@"程序退出"); 程序退出要将登录状态置为未登录状态 } #pragma mark - Network auth status - (void)networkAuthStatus { CTCellularData *cellularData = [[CTCellularData alloc]init]; cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state) { if (state == kCTCellularDataRestricted) { //拒绝 [self networkSettingAlert]; } else if (state == kCTCellularDataNotRestricted) { //允许 } else { //未知 [self unknownNetwork]; } }; } - (void)networkSettingAlert { dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"您尚未授权“%@”访问网络的权限,请前往设置开启网络授权", app_Name] preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { _isShowNetWorkAuth = NO; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { _isShowNetWorkAuth = NO; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; }]]; if (!_isShowNetWorkAuth) { _isShowNetWorkAuth = YES; [RQ_SHARE_FUNCTION.topViewController presentViewController:alertController animated:YES completion:nil]; } }); } - (void)unknownNetwork { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"未知网络" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [RQ_SHARE_FUNCTION.topViewController presentViewController:alertController animated:YES completion:nil]; }); } // app启动或者app从后台进入前台都会调用这个方法 - (void)applicationDidBecomeActive:(UIApplication *)application { if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { }]; } /// 检查版本更新 if (RQ_USER_MANAGER.currentUser) { if (RQ_USER_MANAGER.qzgx == 1) { [RQ_SHARE_FUNCTION checkVersion]; } } else { [RQ_SHARE_FUNCTION checkVersion]; } } // app从后台进入前台都会调用这个方法 - (void)applicationWillEnterForeground:(UIApplication *)application { } - (void)dealloc { } @end