123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // APPdelegateModularForSystemSetting.m
- // jiaPei
- //
- // Created by 张嵘 on 2019/3/26.
- // Copyright © 2019 JCZ. All rights reserved.
- //
- #import "APPdelegateModularForSystemSetting.h"
- #import "RQAppEventAnnotation.h"
- #import <CoreTelephony/CTCellularData.h>
- #if defined(__IPHONE_14_0)
- #import <AppTrackingTransparency/AppTrackingTransparency.h>//适配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
|