[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

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]