// // AppDelegate.m // 我的社保 // // Created by jiaxian_he on 2021/4/17. // #import "AppDelegate.h" #import "UIResponder+SPSBDelegate.h" #import "SPSBGeneralManager.h" #import #import #import #import "AppDelegate+SPSBConfiguration.h" #import #import "SPSBEnumerationProfile.h" #import #import "SPSBKeyProfile.h" #import "SPSBNotificationDelegateManager.h" #import "SPSBColorProfile.h" #import #import "AppDelegate+SPSBHandleData.h" #import "SPSBBusinessManager.h" #import "AppDelegate+SPSBPushNotification.h" #import "AppDelegate+SPSBPopup.h" #import "AppDelegate+SPSBAutoLogin.h" @interface AppDelegate () { AFNetworkReachabilityManager *_networkReachabilityManager; } @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { debugLog(@"%@", NSHomeDirectory()); jxh_setLineColor(spsb_EEEEEE_color()); [[UITextField appearance] setTintColor:spsb_3296FB_color()]; [[UITextView appearance] setTintColor:spsb_3296FB_color()]; [UIScrollView appearance].alwaysBounceVertical = true; if (@available(iOS 15.0, *)) { [UITableView appearance].sectionHeaderTopPadding = 0; } if (@available(iOS 11.0, *)) { if (@available(iOS 15.0, *)) { } else { [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } } #ifdef DEBUG jxh_setClassPrefix(@[@"SPSB"]); #endif spsb_setAppActive(true); [self versionCompatibility];//版本容错 //确保数据库操作在createSQL之后 [self createSQL]; [self handleCache]; [self addNotification]; [self handleReachability];//网络监听 [self localConfiguration];//本地配置 [self thirdPartConfiguration];//第三方配置 [self handlePushWithOptions:launchOptions];//处理推送 [self getADSwitch];//广告开关 [self getProfile];//调用在creatDefinedTabbar后面、处理banner数据 [self judgeLogin]; [self judegePopup]; if (@available(iOS 13,*)) { return true; } else { self.window = spsb_setKeyWindow(nil); return true; } } #pragma mark - Notification - (void)addNotification { spsb_setNotificationKeys(@[SPSBAppStatusNotificationKey, SPSBLoggingNotificationKey]); } - (void)spsb_appNeedLogin { [self judgeLogin]; } - (void)spsb_loggingStatusChanged:(SPSBLoggingStatus)status needCheckOrderBalanceNotPayOrders:(bool)flag { if (status == SPSBLoggingStatusLogin && flag) { [self checkPriceDifferencePaymentNotPayOrders]; } } #pragma mark - reachability - (void)handleReachability { [jxh_userDefaults() setObject:@(SPSBNetworkStatusDefualt) forKey:SPSBNetworkStatusKey]; [jxh_userDefaults() synchronize]; _networkReachabilityManager = [AFNetworkReachabilityManager managerForDomain:@"www.baidu.com"]; @weakify(self) [_networkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { @strongify(self) [self networkChanged:status]; }]; [_networkReachabilityManager startMonitoring]; } - (void)networkChanged:(AFNetworkReachabilityStatus)status { debugLog(@"networkStatus=>%ld", (long)status); SPSBNetworkStatus lastStatus = [[jxh_userDefaults() objectForKey:SPSBNetworkStatusKey] unsignedIntegerValue]; SPSBNetworkStatus currentStatus; switch (status) { case AFNetworkReachabilityStatusReachableViaWiFi: { if (lastStatus == SPSBNetworkStatusNo) { [self networkChangeReachability]; } currentStatus = SPSBNetworkStatusWIFI; } break; case AFNetworkReachabilityStatusReachableViaWWAN: { if (lastStatus == SPSBNetworkStatusNo) { [self networkChangeReachability]; } currentStatus = SPSBNetworkStatusMobile; } break; default: { currentStatus = SPSBNetworkStatusNo; } break; } [jxh_userDefaults() setObject:@(currentStatus) forKey:SPSBNetworkStatusKey]; [jxh_userDefaults() synchronize]; spsb_postNotification(SPSBAppStatusNotificationKey, @selector(spsb_appNetworkChanged:), spsb_appNetworkChanged:currentStatus); } - (void)networkChangeReachability { [self getProfile]; [self judgeLogin]; } #pragma mark - openURL - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler { return [self spsb_responder:application continueUserActivity:userActivity]; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { return [self spsb_responder:app openURL:url]; } #pragma mark - UISceneSession lifecycle - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; } - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions API_AVAILABLE(ios(13.0)){ // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } - (void)applicationWillTerminate:(UIApplication *)application { } - (void)applicationDidBecomeActive:(UIApplication *)application { [self spsb_didBecomeActive:application]; } - (void)applicationWillResignActive:(UIApplication *)application { [self spsb_willResignActive:application]; } - (void)applicationWillEnterForeground:(UIApplication *)application { [self spsb_willEnterForeground:application]; } - (void)applicationDidEnterBackground:(UIApplication *)application { [self spsb_didEnterBackground:application]; } - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { [[SDImageCache sharedImageCache] clearMemory]; } @end