APPdelegateModularForSystemSetting.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // APPdelegateModularForSystemSetting.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/3/26.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "APPdelegateModularForSystemSetting.h"
  9. #import "RQAppEventAnnotation.h"
  10. #import <CoreTelephony/CTCellularData.h>
  11. #if defined(__IPHONE_14_0)
  12. #import <AppTrackingTransparency/AppTrackingTransparency.h>//适配iOS14
  13. #endif
  14. RQAppEventMod(APPdelegateModularForSystemSetting)
  15. @interface APPdelegateModularForSystemSetting ()
  16. @property (nonatomic, readwrite, assign) BOOL isShowNetWorkAuth;
  17. @property (nonatomic, readwrite, assign) UIBackgroundTaskIdentifier backgroundTaskInvalid;
  18. @end
  19. @implementation APPdelegateModularForSystemSetting
  20. - (NSInteger)moduleLevel {
  21. return 0;
  22. }
  23. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  24. [self initMudule];
  25. // [self destroyModule];
  26. return YES;
  27. }
  28. - (void)initMudule {
  29. NSString *version = [UIDevice currentDevice].systemVersion;
  30. if ([version isEqualToString:@"12.1.0"]) {
  31. // 针对 12.1 的iOS系统进行处理
  32. [[UITabBar appearance] setTranslucent:NO];
  33. }
  34. if (@available(iOS 15.0, *)) {
  35. [UITableView appearance].sectionHeaderTopPadding = 0;
  36. }
  37. }
  38. /// 程序挂起
  39. - (void)applicationWillResignActive:(UIApplication *)application {
  40. [EAGLContext setCurrentContext:nil];
  41. }
  42. /// 程序进入后台
  43. - (void)applicationDidEnterBackground:(UIApplication *)application {
  44. if (!myDelegate.scPeriodVC) {
  45. if (myDelegate.timer) {
  46. [myDelegate.timer setFireDate:[NSDate distantFuture]];
  47. }
  48. }else {
  49. if (!myDelegate.scPeriodVC.haveBlueTooth && myDelegate.timer) {
  50. [myDelegate.timer setFireDate:[NSDate distantFuture]];
  51. }
  52. }
  53. myDelegate.isBackgroundTask = YES;
  54. [EAGLContext setCurrentContext:nil];
  55. // 实现如下代码,才能使程序处于后台时被杀死,调用applicationWillTerminate:方法
  56. [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(){}];
  57. }
  58. /// 应用处于后台,所有下载任务完成调用
  59. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
  60. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  61. appDelegate.backgroundSessionCompletionHandler = completionHandler;
  62. }
  63. /// 程序意外退出
  64. - (void)applicationWillTerminate:(UIApplication *)application {
  65. //NSLog(@"程序退出"); 程序退出要将登录状态置为未登录状态
  66. }
  67. #pragma mark - Network auth status
  68. - (void)networkAuthStatus {
  69. CTCellularData *cellularData = [[CTCellularData alloc]init];
  70. cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state) {
  71. if (state == kCTCellularDataRestricted) {
  72. //拒绝
  73. [self networkSettingAlert];
  74. } else if (state == kCTCellularDataNotRestricted) {
  75. //允许
  76. } else {
  77. //未知
  78. [self unknownNetwork];
  79. }
  80. };
  81. }
  82. - (void)networkSettingAlert {
  83. dispatch_async(dispatch_get_main_queue(), ^{
  84. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  85. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  86. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"您尚未授权“%@”访问网络的权限,请前往设置开启网络授权", app_Name] preferredStyle:UIAlertControllerStyleAlert];
  87. [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  88. _isShowNetWorkAuth = NO;
  89. }]];
  90. [alertController addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  91. _isShowNetWorkAuth = NO;
  92. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  93. }]];
  94. if (!_isShowNetWorkAuth) {
  95. _isShowNetWorkAuth = YES;
  96. [RQ_SHARE_FUNCTION.topViewController presentViewController:alertController animated:YES completion:nil];
  97. }
  98. });
  99. }
  100. - (void)unknownNetwork {
  101. dispatch_async(dispatch_get_main_queue(), ^{
  102. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"未知网络" preferredStyle:UIAlertControllerStyleAlert];
  103. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  104. }]];
  105. [RQ_SHARE_FUNCTION.topViewController presentViewController:alertController animated:YES completion:nil];
  106. });
  107. }
  108. // app启动或者app从后台进入前台都会调用这个方法
  109. - (void)applicationDidBecomeActive:(UIApplication *)application {
  110. if (@available(iOS 14, *)) {
  111. [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
  112. }];
  113. }
  114. /// 检查版本更新
  115. if (RQ_USER_MANAGER.currentUser) {
  116. if (RQ_USER_MANAGER.qzgx == 1) {
  117. [RQ_SHARE_FUNCTION checkVersion];
  118. }
  119. } else {
  120. [RQ_SHARE_FUNCTION checkVersion];
  121. }
  122. }
  123. // app从后台进入前台都会调用这个方法
  124. - (void)applicationWillEnterForeground:(UIApplication *)application {
  125. }
  126. - (void)dealloc {
  127. }
  128. @end