[iOS]AppDelegate的分类使用

2024-08-20 23:08
文章标签 使用 分类 ios appdelegate

本文主要是介绍[iOS]AppDelegate的分类使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

AppDelegate是管理整个应用程序生命周期的一个类, 之前我还会在这个类中处理很多第三方库的集成和其他功能, 比如:推送/分享/统计/启动页/引导页/广告/Bugly/版本检查/数据更新 等等. 最后导致AppDelegate非常臃肿, 不利于阅读.
最近发现,使用拓展的方式将各个功能的逻辑分离开来,能够让程序结构更清晰更优雅.

#import "AppDelegate.h"#import "AppDelegate+WeChat.h"
#import "AppDelegate+CheckVersion.h"
#import "AppDelegate+Service.h"
#import "AppDelegate+AliPush.h"
#import "AppDelegate+UMAnalysis.h"
#import "AppDelegate+UMShare.h"
#import "AppDelegate+ShortcutTouch.h"
#import "AppDelegate+Score.h"
#import "AppDelegate+AppSign.h"
#import "AppDelegate+LaunchAD.h"
#import "AppDelegate+StartNumber.h"
#import "AppDelegate+Insterest.h"
#import "AppDelegate+GuidePage.h"
#import "AppDelegate+CheckData.h"
#import "AppDelegate+Pangolin.h"
#import "AppDelegate+NightMode.h"
#import "AppDelegate+Bugly.h"
#import "AppDelegate+ReadTime.h"#import "CYLTabBarController.h"#import "IAPManager.h"
#import <UMShare/UMShare.h>@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];self.tabBarControllerConfig = [[WXYZ_MainTabbarViewController alloc] init];CYLTabBarController *tabBarController = self.tabBarControllerConfig.tabBarController;[self.window setRootViewController:tabBarController];// 检查数据更改[self initCheckData];// 夜览模式[self initNightModeState];// 检查更新[self checkVersionCallBack:^(NSUInteger updateState) {}];// 开启广告[self initADManager];// 启动页[self initLaunchADView];// 引导页[self initGuidePageView];//开启阿里推送[self initAliPushWithApplication:application launchOptions:launchOptions];// 友盟[self initUMAnalysis];// 分享[self initUMShare];// 3D Touch[self initShortcutTouch];// 应用内好评[self initAppStoreScore];// bug统计[self initBugly];// 阅读时长[self initReadingTime];#if WX_Super_Member_Mode || WX_Recharge_Mode// 启动IAP[[IAPManager shared] startManager];
#endif// 微信[self registerWeChat];// 签到[self initUserSign];// 显示沙盒地址[self showHome];return YES;
}- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[self initStartNumber];return YES;
}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {if ([[url host] isEqualToString:@"platformId=wechat"]) {return [[UMSocialManager defaultManager] handleOpenURL:url];}if ([[url host] isEqualToString:@"oauth"]) {return [WXApi handleOpenURL:url delegate:self];}return YES;
}- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {if ([[UMSocialManager defaultManager] handleOpenURL:url]) {return YES;}return [WXApi handleOpenURL:url delegate:self];
}- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {if ([[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation]) {return YES;}return [WXApi handleOpenURL:url delegate:self];
}- (void)applicationWillResignActive:(UIApplication *)application {// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}- (void)applicationDidEnterBackground:(UIApplication *)application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}- (void)applicationWillEnterForeground:(UIApplication *)application {// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}- (void)applicationDidBecomeActive:(UIApplication *)application {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.application.applicationIconBadgeNumber = 0;if (self.forcedUpdateTitle) {[self showUpdateView];}
}- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:./**结束IAP工具类*/[[IAPManager shared] stopManager];
}@end





 

这篇关于[iOS]AppDelegate的分类使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1091435

相关文章

python中的flask_sqlalchemy的使用及示例详解

《python中的flask_sqlalchemy的使用及示例详解》文章主要介绍了在使用SQLAlchemy创建模型实例时,通过元类动态创建实例的方式,并说明了如何在实例化时执行__init__方法,... 目录@orm.reconstructorSQLAlchemy的回滚关联其他模型数据库基本操作将数据添

Spring配置扩展之JavaConfig的使用小结

《Spring配置扩展之JavaConfig的使用小结》JavaConfig是Spring框架中基于纯Java代码的配置方式,用于替代传统的XML配置,通过注解(如@Bean)定义Spring容器的组... 目录JavaConfig 的概念什么是JavaConfig?为什么使用 JavaConfig?Jav

Java使用Spire.Doc for Java实现Word自动化插入图片

《Java使用Spire.DocforJava实现Word自动化插入图片》在日常工作中,Word文档是不可或缺的工具,而图片作为信息传达的重要载体,其在文档中的插入与布局显得尤为关键,下面我们就来... 目录1. Spire.Doc for Java库介绍与安装2. 使用特定的环绕方式插入图片3. 在指定位

Springboot3 ResponseEntity 完全使用案例

《Springboot3ResponseEntity完全使用案例》ResponseEntity是SpringBoot中控制HTTP响应的核心工具——它能让你精准定义响应状态码、响应头、响应体,相比... 目录Spring Boot 3 ResponseEntity 完全使用教程前置准备1. 项目基础依赖(M

Java使用Spire.Barcode for Java实现条形码生成与识别

《Java使用Spire.BarcodeforJava实现条形码生成与识别》在现代商业和技术领域,条形码无处不在,本教程将引导您深入了解如何在您的Java项目中利用Spire.Barcodefor... 目录1. Spire.Barcode for Java 简介与环境配置2. 使用 Spire.Barco

Android使用java实现网络连通性检查详解

《Android使用java实现网络连通性检查详解》这篇文章主要为大家详细介绍了Android使用java实现网络连通性检查的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录NetCheck.Java(可直接拷贝)使用示例(Activity/Fragment 内)权限要求

C# 预处理指令(# 指令)的具体使用

《C#预处理指令(#指令)的具体使用》本文主要介绍了C#预处理指令(#指令)的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录1、预处理指令的本质2、条件编译指令2.1 #define 和 #undef2.2 #if, #el

C#中Trace.Assert的使用小结

《C#中Trace.Assert的使用小结》Trace.Assert是.NET中的运行时断言检查工具,用于验证代码中的关键条件,下面就来详细的介绍一下Trace.Assert的使用,具有一定的参考价值... 目录1、 什么是 Trace.Assert?1.1 最简单的比喻1.2 基本语法2、⚡ 工作原理3

C# IPAddress 和 IPEndPoint 类的使用小结

《C#IPAddress和IPEndPoint类的使用小结》本文主要介绍了C#IPAddress和IPEndPoint类的使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定... 目录一、核心作用网络编程基础类二、IPAddress 类详解三种初始化方式1. byte 数组初始化2. l

C语言逗号运算符和逗号表达式的使用小结

《C语言逗号运算符和逗号表达式的使用小结》本文详细介绍了C语言中的逗号运算符和逗号表达式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 在C语言中逗号“,”也是一种运算符,称为逗号运算符。 其功能是把两个表达式连接其一般形式为:表达