123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // AppDelegate.m
- // 我的社保
- //
- // Created by jiaxian_he on 2021/4/17.
- //
- #import "AppDelegate.h"
- #import "UIResponder+SPSBDelegate.h"
- #import "SPSBGeneralManager.h"
- #import <SDImageCache.h>
- #import <JXHMacro.h>
- #import <NSObject+JXHDeallow.h>
- #import "AppDelegate+SPSBConfiguration.h"
- #import <JXHSystemShortcut.h>
- #import "SPSBEnumerationProfile.h"
- #import <AFNetworkReachabilityManager.h>
- #import "SPSBKeyProfile.h"
- #import "SPSBNotificationDelegateManager.h"
- #import "SPSBColorProfile.h"
- #import <UIView+JXHConvenience.h>
- #import "AppDelegate+SPSBHandleData.h"
- #import "SPSBBusinessManager.h"
- #import "AppDelegate+SPSBPushNotification.h"
- #import "AppDelegate+SPSBPopup.h"
- #import "AppDelegate+SPSBAutoLogin.h"
- @interface AppDelegate ()<SPSBNotificationDelegate> {
- 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<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
- return [self spsb_responder:application continueUserActivity:userActivity];
- }
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)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<UISceneSession *> *)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
|