iOS开发 ☞ UIApplication 生命周期

本文详细介绍了iOS应用程序的各种生命周期状态,包括启动、进入前台、进入后台及终止等阶段,并阐述了各个阶段对应的方法调用及其作用。
test enviroment
A Simulator , A lots of codes like this 

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSLog(@"%@",NSStringFromSelector(_cmd));
    return YES;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    return YES;
}

- (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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

- (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.
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

- (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.
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    NSLog(@"%@",NSStringFromSelector(_cmd));

    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    [d setObject:@"1" forKey:@"3"];
    [d synchronize];
}

启动:

application:willFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:

点击Home键:

applicationWillResignActive:
applicationDidEnterBackground:

从后台恢复:

applicationWillEnterForeground:
applicationDidBecomeActive:

应用在前台,手动杀死程序

applicationWillResignActive:
applicationDidEnterBackground:
applicationWillTerminate:

应用在后台,手动杀死

Do Nothing,the plist file not exits

我们经常滑动屏幕,查看通知,like this:
这里写图片描述

applicationWillResignActive:

如果你点击了某个通知,跳转到了别的应用,当然要执行

applicationDidEnterBackground:

总结一下:
在一个应用程序的整个生命周期,只会调用一次的方法有

application:willFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions:
applicationWillTerminate:

其余的则可能被调用多次,要依据情况而定。

源码地址: https://pan.quark.cn/s/a4b39357ea24 遗传算法 - 简书 遗传算法的理论是根据达尔文进化论而设计出来的算法: 人类是朝着好的方向(最优解)进化,进化过程中,会自动选择优良基因,淘汰劣等基因。 遗传算法(英语:genetic algorithm (GA) )是计算数学中用于解决最佳化的搜索算法,是进化算法的一种。 进化算法最初是借鉴了进化生物学中的一些现象而发展起来的,这些现象包括遗传、突变、自然选择、杂交等。 搜索算法的共同特征为: 首先组成一组候选解 依据某些适应性条件测算这些候选解的适应度 根据适应度保留某些候选解,放弃其他候选解 对保留的候选解进行某些操作,生成新的候选解 遗传算法流程 遗传算法的一般步骤 my_fitness函数 评估每条染色体所对应个体的适应度 升序排列适应度评估值,选出 前 parent_number 个 个体作为 待选 parent 种群(适应度函数的值越小越好) 从 待选 parent 种群 中随机选择 2 个个体作为父方和母方。 抽取父母双方的染色体,进行交叉,产生 2 个子代。 (交叉概率) 对子代(parent + 生成的 child)的染色体进行变异。 (变异概率) 重复3,4,5步骤,直到新种群(parentnumber + childnumber)的产生。 循环以上步骤直至找到满意的解。 名词解释 交叉概率:两个个体进行交配的概率。 例如,交配概率为0.8,则80%的“夫妻”会生育后代。 变异概率:所有的基因中发生变异的占总体的比例。 GA函数 适应度函数 适应度函数由解决的问题决定。 举一个平方和的例子。 简单的平方和问题 求函数的最小值,其中每个变量的取值区间都是 [-1, ...
《基于STM32微控制器集成温湿度监测与显示功能的系统实现方案》 本方案提供了一套完整的嵌入式系统设计参考,实现了环境参数的实时采集、可视化呈现与异常状态提示。系统核心采用意法半导体公司生产的STM32系列32位微控制器作为主控单元,负责协调各外设模块的工作流程。 系统通过数字式温湿度复合传感器周期性获取环境参数,该传感器采用单总线通信协议,具有响应迅速、数据可靠的特点。采集到的数值信息通过两种途径进行处理:首先,数据被传输至有机发光二极管显示屏进行实时图形化显示,该显示屏支持高对比度输出,能够在不同光照条件下清晰呈现当前温度与湿度数值;其次,所有采集数据同时通过通用异步收发传输接口输出,可供上位机软件进行记录与分析。 当监测参数超出预设安全范围时,系统会启动声学警示装置,该装置可发出不同频率的提示音,以区分温度异常或湿度异常状态。所有功能模块的驱动代码均采用模块化设计原则编写,包含完整的硬件抽象层接口定义、传感器数据解析算法、显示缓冲区管理机制以及串口通信协议实现。 本参考实现重点阐述了多外设协同工作的时序控制策略、低功耗数据采集模式的应用方法,以及确保系统稳定性的错误处理机制。代码库中包含了详细的初始化配置流程、中断服务程序设计和各功能模块的应用程序接口说明,为嵌入式环境监测系统的开发提供了可靠的技术实现范例。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值