简体   繁体   English

如何在 Swift5 中关闭应用程序时更改应用程序状态?

[英]How to change the app status when the app is turned off in Swift5?

I have no problem running my app.我运行我的应用程序没有问题。

However, if you click the Share button on my app and complete the share, turn off my app and click on the shared image on another app, it will not go to the login screen.但是,如果您单击我的应用程序上的共享按钮并完成共享,关闭我的应用程序并单击另一个应用程序上的共享图像,则不会 go 到登录屏幕。 Why doesn't it recognize the background status?为什么不识别后台状态?

switch UIApplication.shared.applicationState {
    case .background:
        LoginScreen()
        break
    case .inactive:
        WebViewScreen()
        break
    case .active:
        WebViewScreen()
        break
    default:
        break
}
return true

So if I press the Shared button and go to my app, I can go to the webview screen without fail.因此,如果我按下共享按钮和 go 到我的应用程序,我可以 go 到 webview 屏幕没有失败。 But I don't want to go to the webview screen when the app is off.但是当应用程序关闭时,我不想 go 到 webview 屏幕。

EDIT: 2016 year Document编辑:2016 年文件

Table 2-3 App states State表 2-3 应用状态 State

Description描述

Not running不运行

The app has not been launched or was running but was terminated by the system.该应用程序尚未启动或正在运行,但已被系统终止。

Inactive不活跃

The app is running in the foreground but is currently not receiving events.该应用程序正在前台运行,但当前未接收事件。 (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. (虽然它可能正在执行其他代码。)应用程序通常仅在转换到不同的 state 时短暂停留在此 state 中。

Active积极的

The app is running in the foreground and is receiving events.该应用程序正在前台运行并正在接收事件。 This is the normal mode for foreground apps.这是前台应用程序的正常模式。

Background背景

The app is in the background and executing code.该应用程序在后台并执行代码。 Most apps enter this state briefly on their way to being suspended.大多数应用程序在被暂停的过程中都会短暂输入此 state。 However, an app that requests extra execution time may remain in this state for a period of time.但是,请求额外执行时间的应用程序可能会在此 state 中保留一段时间。 In addition, an app being launched directly into the background enters this state instead of the inactive state.此外,直接在后台启动的应用程序会输入此 state 而不是非活动的 state。 For information about how to execute code while in the background, see Background Execution.有关如何在后台执行代码的信息,请参阅后台执行。

Suspended暂停

The app is in the background but is not executing code.该应用程序在后台,但未执行代码。 The system moves apps to this state automatically and does not notify them before doing so.系统会自动将应用程序移动到此 state,并且在这样做之前不会通知它们。 While suspended, an app remains in memory but does not execute any code.暂停时,应用程序仍保留在 memory 中,但不执行任何代码。

When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.当发生内存不足的情况时,系统可能会在不通知的情况下清除挂起的应用程序,以便为前台应用程序腾出更多空间。

The 2016 Apple document had a status value of ' Notruning '. 2016 Apple 文档的状态值为“ Notruning ”。 Is it gone now?现在没了吗? Is there a substitute status value?有替代的状态值吗?

When app comes over another app like a phone call comes or as in your case via share button.当应用程序出现另一个应用程序时,例如电话来电,或者在您的情况下通过共享按钮。 Your app will go in inactive state and not in background.您的应用程序将 go 在非活动 state 中而不是在后台。 Please put print statement and try to find out in which state your app is in, I suspect it is not in background state.请输入打印语句并尝试找出您的应用程序在哪个 state 中,我怀疑它不在后台 state 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使关闭应用程序也可以快速保存变量 - Save variable in swift even when app is turned off 当应用关闭时,如何从推送通知中获取数据? - How to fetch data from push notification when app is turned off? iPhone关闭或应用卸载时的通知 - Notifications when iPhone is turned off or app is uninstalled 如何在 Swift5 上检查 App Store 中是否有我的应用程序的新版本? - How To check if there is a new version of my app in the App Store on Swift5? swift3如何在应用程序更改为后台状态时更改屏幕 - swift3 how to Change screen when app changes to background status 如何在 iPhone 开机或关机时通知您的应用程序? - How to have your app notified whenever iPhone is turned on or will be turned off? 当iPhone关闭时,WatchKit应用程序会如何处理? - What happens to a WatchKit app when iPhone is turned off? 深度链接关闭时,用户将重定向到ios应用 - Users getting redirected to ios app when deep linking is turned off 当我的应用程序中的位置服务关闭时,如何显示包含设置+取消按钮的UIAlertView? - How to present UIAlertView which contains Settings + Cancel button when location services are turned off in my app? 如何判断用户是否为我的应用关闭了蜂窝数据? - How to tell if the user turned off cellular data for my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM