• iOS应用通过委托对象AppDelegate类在应用周期的不同阶段会回调不同的方法,应用周期分为以下五种状态:

    • Not Running(非运行状态)。应用没有运行或被系统终止。  

    •   Inactive(前台非活动状态)。应用正在进入前台状态,但是还不能接受事件处理。

    •   Active(前台活动状态)。应用进入前台状态,能接受事件处理。

    • Background(后台状态)。应用进入后台后,依然能够执行代码。如果有可执行的代码,就会执行代码,

       如果没有可执行的代码或者将可执行的代码执行完毕,应用会马上进入挂起状态。
      
    •   Suspended(挂起状态)。处于挂起的应用进入一种“冷冻”状态,不能执行代码。如果系统内存不够,

      应用会被终止。 状态跃迁过程中应用回调的方法和本地通知

  •   应用状态改变的回调方法和本地通知
方法 本地通知 说明

application:didFinishLaun- chingWithOptions:

UIApplicationDidFinishLaunching- Notification

应用启动并进行初始化时会调用该方法并发 出通知。这个阶段会实例化根视图控制器

applicationDidBecomeActive:

UIApplicationDidBecomeActive- Notification

应用进入前台并处于活动状态时调用该方法 并发出通知。这个阶段可以恢复UI的状态(例 如游戏状态等)

applicationWillResignActive: 

UIApplicationWillResignActive- Notification

应用从活动状态进入到非活动状态时调用该 方法并发出通知。这个阶段可以保存UI的状 态(例如游戏状态等)

applicationDidEnterBackground:

UIApplicationDidEnterBackground- Notification

应用进入后台时调用该方法并发出通知。这 个阶段可以保存用户数据,释放一些资源(例 如释放数据库资源等)

 applicationWillEnterForeground:  

UIApplicationWillEnterForeground- Notification

应用进入到前台,但是还没有处于活动状态 时调用该方法并发出通知。这个阶段可以恢 复用户数据

applicationWillTerminate: UIApplicationWillTerminate- Notification 应用被终止时调用该方法并发出通知,但内 存清除时除外。这个阶段释放一些资源,也 可以保存用户数据 
  • 具体代码可查看AppDelegate
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
} func applicationWillResignActive(application: UIApplication) {
// 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.
} func applicationDidEnterBackground(application: UIApplication) {
// 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.
} func applicationWillEnterForeground(application: UIApplication) {
// 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.
} func applicationDidBecomeActive(application: UIApplication) {
// 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.
} func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }

iOS开发:应用生命周期的更多相关文章

  1. 【iOS开发】iOS对UIViewController生命周期和属性方法的解析

    iOS对UIViewController生命周期和属性方法的解析 一.引言 作为MVC设计模式中的C,Controller一直扮演着项目开发中最重要的角色,它是视图和数据的桥梁,通过它的管理,将数据有 ...

  2. (转)iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    原文:http://blog.csdn.net/totogo2010/article/details/8048652 iOS应用程序生命周期(前后台切换,应用的各种状态)详解         分类:  ...

  3. iOS对UIViewController生命周期和属性方法的解析

    目录[-] iOS对UIViewController生命周期和属性方法的解析 一.引言 二.UIViewController的生命周期 三.从storyBoard加载UIViewController实 ...

  4. 转:iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: iOS开发进阶2012-10-08 15:35 42691人阅读 评论(30) 收藏 举报 iosapplication任务anima ...

  5. android开发之生命周期

    android开发之生命周期 一:Activity的生命周期: 这几天了了解了安卓Activity的生命周期,对于生命周期有了大概的理解: 一个Activity的生命周期也就是Activity从生成到 ...

  6. Android开发——Activity生命周期

    Android开发--Activity生命周期 Activity作为四大组件之首,也是使用最频繁的一种组件.本文将主要讲解Activity生命周期,包括正常情况下的Activity生命周期和异常情况下 ...

  7. 浅尝Spring注解开发_Bean生命周期及执行过程

    Spring注解开发 浅尝Spring注解开发,基于Spring 4.3.12 包含Bean生命周期.自定义初始化方法.Debug BeanPostProcessor执行过程及在Spring底层中的应 ...

  8. iOS - ViewController的生命周期

    iOS SDK中提供很多原生的ViewController,大大提高了我们的开发效率:那么下面我们就根据开发中我们常用的ViewController谈一谈它的生命周期: (一)按照结构和用法可以对iO ...

  9. iOS控制器的生命周期分析和使用

    转自http://blog.csdn.net/qijianli/article/details/7826979 iOS的SDK中提供很多原生ViewController,大大提高了我们的开发效率,下面 ...

  10. [转]iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    转载地址:http://blog.csdn.net/totogo2010/article/details/8048652 iOS的应用程序的生命周期,还有程序是运行在前台还是后台,应用程序各个状态的变 ...

随机推荐

  1. firefox常用扩展、脚本

    1.AutoPopup.uc.js:鼠标移到菜单和下拉箭头上自动弹出下拉菜单 2.moveButton.uc.js:移动或克隆按钮或菜单到火狐浏览器的任意位置 moveButton.uc.js使用说明 ...

  2. 关于12306登陆页面dynamicJs的获取

    今天帮与一个朋友探讨此事,刚开始一直是以为访问404,但是发现返回为200,没有问题,后来才知道朋友想了解的是为何浏览器可以获取到/otn/dynamicJs,但是自己手动获取就获取不到了 找了很久r ...

  3. Uyuw's Concert POJ2451

    裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...

  4. tomcat7.0.47 修改tomcat窗口名称

    最近使用的是 apache - tomcat 集群,为了方便管理上想要修改tomcat命令窗口的名字来区分不同的tomcat,我在网上找了些资料,顺便总结一下,方便自己,方便他人 修改如下: 找到to ...

  5. .NET 轻松实现HTML的绝对过滤之SafeHelper

    当今网页中经常使用到网页编辑器,因为人们需要在网页中插入图片,视频,样式等html代码内容,这使得网页的信息更加丰富.随之而来的,也给程序开发者带来了不少麻烦,因为提交的html中难免会出现不安全标记 ...

  6. Codeforces Round #327 (Div. 2) E. Three States

    题目链接: 题目 E. Three States time limit per test:5 seconds memory limit per test:512 megabytes 问题描述 The ...

  7. c#中获取服务器IP,客户端IP以及其它

    客户端ip:Request.ServerVariables.Get("Remote_Addr").ToString();客户端主机名:Request.ServerVariables ...

  8. 【BZOJ】【3524】【POI2014】Couriers

    可持久化线段树 裸可持久化线段树,把区间第K大的rank改成num即可……(往儿子走的时候不减少) 苦逼的我……MLE了一次(N*30),RE了一次(N*10)……数组大小不会开…… 最后开成N*20 ...

  9. vs2010中臃肿的ipch和sdf文件

    使用VS2010建立C++解决方案时,会生成SolutionName.sdf和一个叫做ipch的文件夹,这两个文件再加上*.pch等文件使得工程变得非常的庞大,一个简单的程序都会占用几十M的硬盘容量, ...

  10. intellij idea 14 ULTIMATE 注册码

    Name:happy KEY:63763-YCO0I-QR4TV-G4I3E-4XGK9-GQSQ3