简体   繁体   中英

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. 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. But I don't want to go to the webview screen when the app is off.

EDIT: 2016 year Document

Table 2-3 App states 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.

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. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive 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. While suspended, an app remains in memory but does not execute any code.

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 '. 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. Please put print statement and try to find out in which state your app is in, I suspect it is not in background state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM