重温一下iOS应用的生命周期

说在前面:

5个状态:not runing 非运行;inactive :前台非活动;active:前台活动;background:后台状态;suspended:挂起状态

在状态变化种,APP会回调AppDelegate中的相关方法,并发出对应通知。

场景1:应用启动:

状态变化:not runing ->inactive->active,在not runing->inactive过程中,调用didFinishLaunchingWithOptions,发出UIApplicationDidFinishLaunchingNotification通知

inactve->active:调用didBecomeActive,发出UIApplicationDidBecomeActiveNotification通知

场景2:应用退出(点击HOME键)

状态变化1:可在后台运行并挂起:active->inactive->background->suspended

active->inactive:回调WillResignActive并发出相应通知

inactive->background:willEnterBackground

background->suspended:didEnterBackground 并发出相应通知

状态变化1:不可在后台运行并挂起:active->inactive->background->suspended->not runing

active->inactive:回调WillResignActive并发出相应通知

inactive->background:willEnterBackground

background->suspended:didEnterBackground 并发出相应通知

suspended->not runing:willTerminate,并发出响应通知

场景3:挂起被用户唤醒

状态变化:suspended->background->inactive->active

场景4:应用终止

backbround->suspended->not runing

你可能感兴趣的:(重温一下iOS应用的生命周期)