Need clarification about UIApplicationState

后端 未结 3 1521
不知归路
不知归路 2020-12-15 07:34

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) A

相关标签:
3条回答
  • 2020-12-15 07:51

    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.

    0 讨论(0)
  • 2020-12-15 07:51

    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.

    0 讨论(0)
  • 2020-12-15 07:58

    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.

    0 讨论(0)
提交回复
热议问题