UIApplicationDidEnterBackgroundNotification

Amit Agrawal picture Amit Agrawal · Feb 1, 2011 · Viewed 22.8k times · Source

whats the use of UIApplicationDidEnterBackgroundNotification in iPhone app or how we can take benifit from it

Answer

Oded Ben Dov picture Oded Ben Dov · Feb 10, 2011

This notification means the user "quit" your app on an iPhone 4 - It happens when a phone call or text message comes in and user accepts the interruption (answers/replies), or when the user has pressed the Home button.

I found this link on SO that shows the interaction between all states, and the appropriate notifications: http://www.drobnik.com/touch/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/

To make use of this notification you can implement applicationDidEnterBackground as @Antwan suggested (in your UIApplicationDelegate class - that's the main class).

Alternatively you could set up a notification handler wherever you want/need in your code:

[[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(handleEnteredBackground:) 
                                             name: UIApplicationDidEnterBackgroundNotification
                                           object: nil];

Good luck!

Oded.