Search code examples
iosswiftios-background-mode

Different background modes in iOS


To recognize my app entered Background Mode [One short Home-Button click] I use this function:

func applicationDidEnterBackground(_ application: UIApplication) {
    //...
}

But how can I recognize my app entered App Switching Mode [Two short Home-Button clicks]? The method applicationDidEnterBackground is not called in this case.


Solution

  • Try this:

        func applicationWillResignActive(_ application: UIApplication) {
            // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
            // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
        }