Application state enumeration UIApplicationState
:
1 typedef enum UIApplicationState : NSInteger { 2 UIApplicationStateActive, 3 UIApplicationStateInactive, 4 UIApplicationStateBackground 5 } UIApplicationState;
UIApplicationStateActive :应用程序运行在前台,目前接收事件。
UIApplicationStateInactive:应用程序运行在前台但不接收事件。这可能发生的由于一个中断或因为应用过渡到后台或者从后台过度到前台。
<1> call comes in or other interrupt events
<2> from the foreground into the background of excessive event
<3> from the background into the foreground of excessive event
UIApplicationStateBackground :应用程序在后台运行
Obtaining status codes:
1, the global acquisition mode
1 UIApplicationState state = [UIApplication sharedApplication].applicationState; 2 if(state == UIApplicationStateActive){ 3 //code here... 4 }else if(state == UIApplicationStateBackground){ 5 //code here... 6 }else{ 7 //code here... 8 }
2, application lifecycle acquisition
1 #AppDelegate.m 2 3 - (void)applicationWillResignActive:(UIApplication *)application { 4 UIApplicationState state = application.applicationState; 5 if(state == UIApplicationStateActive){ 6 //code here... 7 }else if(state == UIApplicationStateBackground){ 8 //code here... 9 }else{ 10 //code here... 11 } 12 }