Explore Library
Code QuizAdvanced

Wrong Method for Background Work

Spot the app lifecycle mistake when handling the transition into the background state.

Codeswift
class AppDelegate: UIResponder, UIApplicationDelegate {

    // Goal: run cleanup ONLY when the app actually enters the background
    func applicationWillResignActive(_ application: UIApplication) {
        print("App entered background")
        saveUserData()
        stopBackgroundTasks()
    }

    func saveUserData() { /* persist state */ }
    func stopBackgroundTasks() { /* tear down tasks */ }
}

The background cleanup runs at the wrong time. What is the bug?