How can I listen for an event when a user opens the app switcher (the UI that comes up when a user double taps on the home button) on iOS.
I though UIApplicationDidEnterBackgroundNotification would fire, but it doesn't fire when I open the app switcher. It only fires when I minimize the app by tapping the home button once.
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "onPause",
name: UIApplicationDidEnterBackgroundNotification,
object:nil)
func onPause() {
//Not invoked when app switcher is opened
}
Open the App Switcher to quickly switch from one open app to another on your iPhone. When you switch back, you can pick up right where you left off.
To detect if an iOS application is in background or foreground we can simply use the UIApplication just like we can use it to detect many other things like battery state, status etc. The shared. application state is an enum of type State, which consists of the following as per apple documentation.
You should receive a UIApplicationWillResignActiveNotification
in that case. Your app is no longer the active app, but has not yet moved to the background.
If the user goes back to your app you'll get a UIApplicationDidBecomeActiveNotification
when the app becomes active again. If the user does swap to another app, or select the springboard, then you should get a UIApplicationDidEnterBackgroundNotification
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With