Explore Library
Code QuizAdvanced

Saving State on Background

Spotting the wrong lifecycle hook used to persist state when the app leaves the foreground.

Codeswift
import UIKit

class AppDelegate: UIResponder, UIApplicationDelegate {

    // Goal: save user progress whenever the app leaves the
    // foreground and moves to the background state.
    func applicationDidBecomeActive(_ application: UIApplication) {
        GameManager.shared.saveProgress()
        print("Progress saved before backgrounding")
    }
}

The goal is to save progress when the app enters the background, but this code doesn't do that. What is the bug?