12

How do I detect that an app has launched into the background state? Needless to say regular apps cannot do this, only a small set of apps of the proper type can, and it is not an ideal situation. In particular Newsstand apps do this.

  • 2
    Can you give an example of an app that launches into the background? I don't understand what you mean. – jrturton Dec 12 '11 at 19:45
  • Are you talking about something MobileSubstrate based? – Richard J. Ross III Dec 12 '11 at 19:58
  • VOIP app with the proper voip background modes plist key set. – hotpaw2 Dec 12 '11 at 20:01
  • @hotpaw2 - so you think this means an app that has gone into the background and will still be running? That does make more sense than one that was _launched_ into the background. Can the question be edited to reflect this if it is the case, Mithras? – jrturton Dec 12 '11 at 20:05
  • And the answer to the puzzle is.... Newsstand apps do this. –  Dec 12 '11 at 20:09
  • Nowadays apps supporting quickreply in push notifications also start in background. – fabb Feb 07 '18 at 13:35

1 Answers1

24

Hard to believe nobody answered this correctly yet. From the iOS App Progamming Guide:

To determine whether your app is launching into the foreground or background, check the applicationState property of the shared UIApplication object in your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: delegate method. When the app is launched into the foreground, this property contains the value UIApplicationStateInactive. When the app is launched into the background, the property contains the value UIApplicationStateBackground instead. You can use this difference to adjust the launch-time behavior of your delegate methods accordingly.

XJones
  • 21,959
  • 10
  • 67
  • 82
  • Updated link: [link] (https://developer.apple.com/documentation/uikit/uiapplication/1623003-applicationstate) – Cesar Maiorino Jul 05 '17 at 20:16
  • this used to work but the UISceneManager messes this up. also, the scene manager loads the view even if launched into background, this shouldn't be happening at all. – Hogdotmac May 11 '20 at 14:09
  • @Hogdotmac I'll bite - what's UISceneManager? Did you mean some other type, or is this something outside of iOS? – Dave Nottage Jan 04 '21 at 02:10