iOS应用程序的状态
- iOS应用程序一共有五种状态:
- Not Running 程序还没运行
- Inactive 程序运行在foreground但没有接收事件
- Active 程序运行在foreground接收事件
- Background 程序运行在background正在执行代码
- Suspended 程序运行在background没有执行代码
-
iOS应用程序状态变化会回调APPDelegate中的方法,但不是每一种状态变化都会有对应的方法(上图的红框的两个变化就没有对应的方法)
application:didFinishLaunchingWithOptions:
Not Running -> InactiveapplicationDidBecomeActive:
Inactive -> ActiveapplicationWillResignActive:
Active -> InactiveapplicationDidEnterBackground:
Background -> SuspendedapplicationWillEnterForeground:
Background -> InactiveapplicationWillTerminate:
Suspended -> Not Running
-
常见的应用状态变化场景
- 程序第一次启动(或者被杀掉以后启动):
Not Running -> Inactive -> Active - 点击Home键(没有在Inof.plist中设置Application does not run in background):
Active -> Inactive -> Background -> Suspended - 点击Home键(在Inof.plist中设置Application does not run in background为
YES
,应用不能运行在后台,进入后台后会立即进入Not Running):
Active -> Inactive -> Background -> Suspended -> Not Running - 挂起重新运行
Suspended -> Background -> Inactive -> Active - 内存清除(杀掉应用或删除应用)
Suspended -> Not Running - 应用之间的切换 Active -> Inactive Inactive -> Active
- 点击Home键(在Inof.plist中设置Application does not run in background为
YES
,应用不能运行在后台,进入后台后会立即进入Not Running):
Active -> Inactive -> Background -> Suspended -> Not Running
- 程序第一次启动(或者被杀掉以后启动):
-
可通过在APPDelegate的回调方法中打印数据,来查看应用状态变化
|
|
文章作者 andyron
上次更新 2024-07-16
许可协议 原创文章,如需转载请注明文章作者和出处。谢谢!