需要澄清 UIApplicationState

发布于 2024-12-13 04:47:21 字数 743 浏览 5 评论 0原文

我需要您的帮助来澄清我对应用程序各种状态的理解。我将阐述我的解释 - 但请随时纠正我。

1) 应用程序启动并在前台运行:state = UIApplicationStateActive
2)用户按下主页按钮:state = UIApplicationStateBackground(???)。

 Debug stmt in my app shows it to be Active

3)用户双击Home并杀死应用程序:state = UIApplicationStateInactive

如果情况2的值确实是Active,那么什么时候该值设置为Background?

我的基于位置的应用程序依赖此值来为用户采取适当的操作。

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

问候, 萨姆.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

却一份温柔 2024-12-20 04:47:21

当用户点击应用图标时,应用会短暂经历 UIApplicationStateInactive 过渡状态,然后变为 UIApplicationStateActive。这是应用程序准备好向用户显示的地方。

当应用程序打开时,应用程序状态为UIApplicationStateActive

如果用户按下主页按钮并返回到跳板(主屏幕),或者应用程序被某些事件(例如电话呼叫)中断,则应用程序状态将转换回 UIApplicationStateInactive

为了使应用程序的应用程序状态变为 UIApplicationStateBackground,您的应用程序必须注册后台进程。了解如何在后台设置您的位置服务。

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.

不顾 2024-12-20 04:47:21

苹果文档:
UIApplicationState 常量参考

  • Swift: .Active | Objective-C:UIApplicationStateActive

应用程序正在前台运行,当前正在接收事件。

适用于 iOS 4.0 及更高版本。

  • Swift:.Inactive | Objective-C:UIApplicationStateInactive

应用程序正在前台运行,但未接收事件。这
可能会由于中断或应用程序正在运行而发生
切换到后台或从后台切换。

适用于 iOS 4.0 及更高版本。

  • Swift:.Background | Objective-C:UIApplicationStateBackground

应用程序正在后台运行。

适用于 iOS 4.0 及更高版本。

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.

橙味迷妹 2024-12-20 04:47:21

一些示例:

UIApplicationStateActive - 应用程序正在前台运行。简单的。

UIApplicationStateInactive - 例如 应用程序位于后台,并通过推送通知打开(转换 atm)。或者控制/通知中心显示在您的应用程序上方。你大概看到了,它在前景中。

UIApplicationStateBackground - 应用程序在后台,但仍在运行。 例如播放音乐。然后 - 这可能需要一段时间(取决于您在后台运行的进程),但在某一时刻您的应用程序会被终止。您将在最小化的应用程序之间看到应用程序的快照和图标,但应用程序将首先再次启动。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文