Applicationwillenterforeground Vs. Applicationdidbecomeactive, Applicationwillresignactive Vs. Applicationdidenterbackground

differentiate between single click and double click on Home button in iOS

Nope. You can only see when your app enters the background (or terminates). You can't see why.

applicationDidEnterBackground and applicationWillEnterForeground method are not called when pressed home button in iOS simulator

The reason why applicationDidEnterBackground: and applicationDidEnterForeground: are never called is because these methods are used in joint with Application does not run in background this option can be found in your ***-info.plist. If this option is set to YES than your app will never call these methods, because these when you press the home button with an app that has set the option to YES the instance of the app that is running will get terminated so everytime you press the home button and then select the app icon a new instance is being created so it is using applicationWillTerminate:.

The methods that Kirti mali has said would also be the incorrect methods to use for want you are after, the reason being is that applicationDidBecomeActive: and applicationWillResignActive: are used when something like when you answer a phone call. The instance running is not terminated neither is it sent to the background. The instance is paused until the user has finished on that call when it will become active again.

So the solution to this would be if you want the app to run in background would be to change the option "Application does not run in background" in the ***-info.plist to be NO just applicationDidBecomeActive: and applicationWillResignActive: is the wrong way for these methods to be used.

Please see the apple documentation on UIApplicationDelegate to get a better understanding of these methods.

When an app is launched from the background, will applicationDidBecomeActive get called?

In most cases it should, but it's good to be careful about that. Here's a list of cases in which applicationDidBecomeActive and applicationWillEnterForeground should be called (ref)

applicationWillEnterForeground is called:

  • when app is relaunched(comes from background to foreground)
  • This method is not invoked when app starts for the first time i.e when applicationDidFinishLaunch is called but only when comes from background

applicationDidBecomeActive is called

  • when app is first launched after didFinishLaunching.
  • after applicationWillEnterForeground if there’s no URL to handle.
  • after application:handleOpenURL: is called.
  • after applicationWillResignActive if user ignores interruption like a phone call or SMS.
  • after disappearing of alertView anywhere from the application


Related Topics



Leave a reply



Submit