Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

uiapplication - Need clarification about UIApplicationState

I need your help in clarifying my understanding of the various states of an app. I am going to state my interpretation - but please feel free to correct me.

1) App is launched and running in the foreground: state = UIApplicationStateActive
2) User pushes home button: state = UIApplicationStateBackground (????).

 Debug stmt in my app shows it to be Active

3) User double-taps Home and kills the app: state = UIApplicationStateInactive

If the value for case 2 is indeed Active, then when is the value set to Background?

My location-based app relies on this values to take appropriate action for the user.

if ( ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ||
    ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)      ) {
    // isInBackground = YES;
    //  ------ UI not available
}
else {
   // isInBackground = NO;
   //   ------ UI is available
}

Regards, Sam.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When the user taps on the app icon, the app briefly goes through a transitional state of UIApplicationStateInactive on its way to becoming UIApplicationStateActive. This is where the app gets itself ready to display to the user.

When the app is open, the application state is UIApplicationStateActive.

If the user presses the home button, and is returned to the springboard (home screen), or the application is interrupted by something, such as a phone call, the application state transitions back to UIApplicationStateInactive.

For the application state of your app to become UIApplicationStateBackground, your application would have to register for a background process. Look into how to background your location services.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...