Listen for event when user opens app switcher on iOS
Asked Answered
A

1

9

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
}
Amitosis answered 27/6, 2016 at 21:48 Comment(0)
M
9

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.

Membership answered 27/6, 2016 at 22:15 Comment(2)
Sorry, that should read "...another app has not yet moved to the foreground."Membership
How about "the app has not yet moved to the background" ?Dendrite

© 2022 - 2024 — McMap. All rights reserved.