AppDelegate.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // AppDelegate.m
  3. // 我的社保
  4. //
  5. // Created by jiaxian_he on 2021/4/17.
  6. //
  7. #import "AppDelegate.h"
  8. #import "UIResponder+SPSBDelegate.h"
  9. #import "SPSBGeneralManager.h"
  10. #import <SDImageCache.h>
  11. #import <JXHMacro.h>
  12. #import <NSObject+JXHDeallow.h>
  13. #import "AppDelegate+SPSBConfiguration.h"
  14. #import <JXHSystemShortcut.h>
  15. #import "SPSBEnumerationProfile.h"
  16. #import <AFNetworkReachabilityManager.h>
  17. #import "SPSBKeyProfile.h"
  18. #import "SPSBNotificationDelegateManager.h"
  19. #import "SPSBColorProfile.h"
  20. #import <UIView+JXHConvenience.h>
  21. #import "AppDelegate+SPSBHandleData.h"
  22. #import "SPSBBusinessManager.h"
  23. #import "AppDelegate+SPSBPushNotification.h"
  24. #import "AppDelegate+SPSBPopup.h"
  25. #import "AppDelegate+SPSBAutoLogin.h"
  26. @interface AppDelegate ()<SPSBNotificationDelegate> {
  27. AFNetworkReachabilityManager *_networkReachabilityManager;
  28. }
  29. @end
  30. @implementation AppDelegate
  31. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  32. debugLog(@"%@", NSHomeDirectory());
  33. jxh_setLineColor(spsb_EEEEEE_color());
  34. [[UITextField appearance] setTintColor:spsb_3296FB_color()];
  35. [[UITextView appearance] setTintColor:spsb_3296FB_color()];
  36. [UIScrollView appearance].alwaysBounceVertical = true;
  37. if (@available(iOS 15.0, *)) {
  38. [UITableView appearance].sectionHeaderTopPadding = 0;
  39. }
  40. if (@available(iOS 11.0, *)) {
  41. if (@available(iOS 15.0, *)) {
  42. } else {
  43. [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  44. }
  45. }
  46. #ifdef DEBUG
  47. jxh_setClassPrefix(@[@"SPSB"]);
  48. #endif
  49. spsb_setAppActive(true);
  50. [self versionCompatibility];//版本容错
  51. //确保数据库操作在createSQL之后
  52. [self createSQL];
  53. [self handleCache];
  54. [self addNotification];
  55. [self handleReachability];//网络监听
  56. [self localConfiguration];//本地配置
  57. [self thirdPartConfiguration];//第三方配置
  58. [self handlePushWithOptions:launchOptions];//处理推送
  59. [self getADSwitch];//广告开关
  60. [self getProfile];//调用在creatDefinedTabbar后面、处理banner数据
  61. [self judgeLogin];
  62. [self judegePopup];
  63. if (@available(iOS 13,*)) {
  64. return true;
  65. } else {
  66. self.window = spsb_setKeyWindow(nil);
  67. return true;
  68. }
  69. }
  70. #pragma mark - Notification
  71. - (void)addNotification {
  72. spsb_setNotificationKeys(@[SPSBAppStatusNotificationKey, SPSBLoggingNotificationKey]);
  73. }
  74. - (void)spsb_appNeedLogin {
  75. [self judgeLogin];
  76. }
  77. - (void)spsb_loggingStatusChanged:(SPSBLoggingStatus)status needCheckOrderBalanceNotPayOrders:(bool)flag {
  78. if (status == SPSBLoggingStatusLogin && flag) {
  79. [self checkPriceDifferencePaymentNotPayOrders];
  80. }
  81. }
  82. #pragma mark - reachability
  83. - (void)handleReachability {
  84. [jxh_userDefaults() setObject:@(SPSBNetworkStatusDefualt) forKey:SPSBNetworkStatusKey];
  85. [jxh_userDefaults() synchronize];
  86. _networkReachabilityManager = [AFNetworkReachabilityManager managerForDomain:@"www.baidu.com"];
  87. @weakify(self)
  88. [_networkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  89. @strongify(self)
  90. [self networkChanged:status];
  91. }];
  92. [_networkReachabilityManager startMonitoring];
  93. }
  94. - (void)networkChanged:(AFNetworkReachabilityStatus)status {
  95. debugLog(@"networkStatus=>%ld", (long)status);
  96. SPSBNetworkStatus lastStatus = [[jxh_userDefaults() objectForKey:SPSBNetworkStatusKey] unsignedIntegerValue];
  97. SPSBNetworkStatus currentStatus;
  98. switch (status) {
  99. case AFNetworkReachabilityStatusReachableViaWiFi: {
  100. if (lastStatus == SPSBNetworkStatusNo) {
  101. [self networkChangeReachability];
  102. }
  103. currentStatus = SPSBNetworkStatusWIFI;
  104. }
  105. break;
  106. case AFNetworkReachabilityStatusReachableViaWWAN: {
  107. if (lastStatus == SPSBNetworkStatusNo) {
  108. [self networkChangeReachability];
  109. }
  110. currentStatus = SPSBNetworkStatusMobile;
  111. }
  112. break;
  113. default: {
  114. currentStatus = SPSBNetworkStatusNo;
  115. }
  116. break;
  117. }
  118. [jxh_userDefaults() setObject:@(currentStatus) forKey:SPSBNetworkStatusKey];
  119. [jxh_userDefaults() synchronize];
  120. spsb_postNotification(SPSBAppStatusNotificationKey, @selector(spsb_appNetworkChanged:), spsb_appNetworkChanged:currentStatus);
  121. }
  122. - (void)networkChangeReachability {
  123. [self getProfile];
  124. [self judgeLogin];
  125. }
  126. #pragma mark - openURL
  127. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  128. return [self spsb_responder:application continueUserActivity:userActivity];
  129. }
  130. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
  131. return [self spsb_responder:app openURL:url];
  132. }
  133. #pragma mark - UISceneSession lifecycle
  134. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
  135. // Called when a new scene session is being created.
  136. // Use this method to select a configuration to create the new scene with.
  137. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  138. }
  139. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0)){
  140. // Called when the user discards a scene session.
  141. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  142. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  143. }
  144. - (void)applicationWillTerminate:(UIApplication *)application {
  145. }
  146. - (void)applicationDidBecomeActive:(UIApplication *)application {
  147. [self spsb_didBecomeActive:application];
  148. }
  149. - (void)applicationWillResignActive:(UIApplication *)application {
  150. [self spsb_willResignActive:application];
  151. }
  152. - (void)applicationWillEnterForeground:(UIApplication *)application {
  153. [self spsb_willEnterForeground:application];
  154. }
  155. - (void)applicationDidEnterBackground:(UIApplication *)application {
  156. [self spsb_didEnterBackground:application];
  157. }
  158. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
  159. [[SDImageCache sharedImageCache] clearMemory];
  160. }
  161. @end