Return background to foreground

how to stop background mode and reactivate the app in foreground

func applicationDidEnterBackground(_ application: UIApplication) {
var finished = false
var bgTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier(rawValue: 0);
bgTask = application.beginBackgroundTask(withName:"MyBackgroundTask", expirationHandler: {() -> Void in
// Time is up.
if bgTask != UIBackgroundTaskIdentifier.invalid {
// Do something to stop our background task or the app will be killed
finished = true
}
})

    // Perform your background task here
    print("The task has started")
    while !finished {
        print("Not finished")
        // when done, set finished to true
        // If that doesn't happen in time, the expiration handler will do it for us
    }
    
    // Indicate that it is complete
    application.endBackgroundTask(bgTask)
    if bgTask != UIBackgroundTaskIdentifier.invalid {
        // Do something to stop our background task or the app will be killed
        bgTask = UIBackgroundTaskIdentifier.invalid
        finished = true
    }
    
}

I’m not sure I understand your question properly but it definitely seems to be related to background execution on iOS, and not the Swift language itself. As such, you might get better responses asking this somewhere other than Swift Forums, which is really focused on the Swift language. If you post this to the App Frameworks > iOS Multitasking topic area on DevForums, I take a proper look the next time I swing by.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

With this app work good, but when i get back in foreground all function are disable... who can i get work in foreground?