枚举类型:
typedef NS_ENUM(NSInteger, UIApplicationState) {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
}
状态获取方式:
UIApplicationState state = [UIApplication sharedApplication].applicationState;
1、 UIApplicationStateActive
应用在前台运行时的状态
2、 UIApplicationStateInactive
应用的待激活状态
a、下拉通知栏触发;
b、双击home触发;
c、上拉弹出任务栏触发;
d、锁屏触发
锁屏触发:UIApplicationWillResignActiveNotification --> UIApplicationDidEnterBackgroundNotification --> applicationProtectedDataWillBecomeUnavailable(仅在设置了密码时触发)
返回前台:UIApplicationWillEnterForegroundNotification-->applicationProtectedDataDidBecomeAvailable(仅在设置了密码时触发) -->UIApplicationDidBecomeActiveNotification
3、 UIApplicationStateBackground
应用在后台的状态
a、按home键进入后台触发;
b、启动其他应用触发
此操作通知触发顺序为:
进入后台:UIApplicationWillResignActiveNotification --> UIApplicationDidEnterBackgroundNotification
经历状态:Active-->Inactive-->Background-->Suspended
Active-->Inactive
调用 applicationWillResignActive: 发送:UIApplicationWillResignActiveNotification
Background-->Suspended
调用 applicationDidEnterBackground: 发送:UIApplicationDidEnterBackgroundNotification
返回前台:UIApplicationWillEnterForegroundNotification --> UIApplicationDidBecomeActiveNotification
经历状态:Suspended-->Background-->Inactive-->Active
Background-->Inactive
调用 applicationWillEnterForeground: 发送:UIApplicationWillEnterForegroundNotification
Inactive-->Active
调用 applicationDidBecomeActive: 发送:UIApplicationDidBecomeActiveNotification
点击应用图标状态变化:Not running-->Inactive-->Active
Not running --> Inactive
调用 application:didFinishLaunchingWithOptions: 发送:UIApplicationDidFinishLaunchingNotification
Inactive-->Active
调用 applicationDidBecomeActive: 发送:UIApplicationDidBecomeActiveNotification
home键回后台:
2018-11-02 16:10:52:490 XXX[3216:695434] ==========noti willResignActiveNotification
2018-11-02 16:10:53:062 XXX[3216:695434] ==========noti didEnterBackgroundNotification
home键回后台后回前台:
2018-11-02 16:11:30:206 XXX[3216:695434] ==========noti willEnterForegroundNotification
2018-11-02 16:11:30:473 XXX[3216:695434] ==========noti didBecomeActiveNotification
锁屏:
2018-11-02 16:12:01:264 XXX[3216:695434] ==========noti willResignActiveNotification
2018-11-02 16:12:01:295 XXX[3216:695434] ==========noti didEnterBackgroundNotification
applicationProtectedDataWillBecomeUnavailable
锁屏后回前台:
2018-11-02 16:12:43:612 XXX[3216:695434] ==========noti willEnterForegroundNotification
applicationProtectedDataDidBecomeAvailable
2018-11-02 16:12:44:164 XXX[3216:695434] ==========noti didBecomeActiveNotification
下拉:
2018-11-02 16:13:07:262 XXX[3216:695434] ==========noti willResignActiveNotification
2018-11-02 16:13:08:279 XXX[3216:695434] ==========noti didBecomeActiveNotification
2018-11-02 16:13:08:296 XXX[3216:695434] ==========noti willResignActiveNotification
返回:
2018-11-02 16:13:52:286 XXX[3216:695434] ==========noti didBecomeActiveNotification
上拉:
2018-11-02 16:14:06:682 XXX[3216:695434] ==========noti willResignActiveNotification
返回
2018-11-02 16:14:23:964 XXX[3216:695434] ==========noti didBecomeActiveNotification
网友评论