Need clarification about UIApplicationState

坚强是说给别人听的谎言 提交于 2019-11-28 23:22:17

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.

Apple documentation: UIApplicationState Constants Reference

  • Swift: .Active | Objective-C: UIApplicationStateActive

The app is running in the foreground and currently receiving events.

Available in iOS 4.0 and later.

  • Swift: .Inactive | Objective-C: UIApplicationStateInactive

The app is running in the foreground but is not receiving events. This might happen as a result of an interruption or because the app is transitioning to or from the background.

Available in iOS 4.0 and later.

  • Swift: .Background | Objective-C: UIApplicationStateBackground

The app is running in the background.

Available in iOS 4.0 and later.

Some examples:

UIApplicationStateActive - App is running in foreground. Simple.

UIApplicationStateInactive - E.g. App was in the background and is opening through a push notification (transitioning atm). Or the control/notification center is presented above your app. You kind of see it, is in foreground.

UIApplicationStateBackground - App is in the background, but still running. E.g. playing music. Then - this can take a while or not (depending on process you are running in background), but in one point your app is killed. You will see app's snapshot and icon between minimized apps, but the app will be launch again first.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!