UIApplicationDidEnterBackgroundNotification

what to use UIApplicationDidEnterBackgroundNotification in an application for iPhone or how we can benefit from it

+7
source share
2 answers

This notification means that the user has β€œstopped” your application on iPhone 4. This occurs when a phone call or text message arrives and the user accepts an interruption (answers / answers) or when the user clicks the Home button.

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

To use this notification, you can implement applicationDidEnterBackground as suggested by @Antwan (in your class, UIApplicationDelegate is the main class).

Alternatively, you can configure the notification handler where you want / need your code:

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

Good luck

Oded.

+25
source

From apple documentation .

Informs the delegate that the application is now in the background.

 - (void)applicationDidEnterBackground:(UIApplication *)application 

Parameters expression Instance of a singleton application.

Discussion In iOS 4.0 and later, this method is called instead of the applicationWillTerminate: method when a user terminates an application that supports background execution. You should use this method to free up shared resources, save user data, invalidate timers, and store enough information about the state of the application to restore your application to its current state if it stops later. You should also disable application UI updates and avoid using certain types of system shares (such as a user contact database). It is also imperative to avoid using OpenGL ES in the background.

Your implementation of this method has about five seconds to complete any tasks and return. If you need extra time to complete any final tasks, you can request additional execution time from the system by calling beginBackgroundTaskWithExpirationHandler: In practice, you should return as soon as possible with applicationDidEnterBackground: If the method does not return before the time runs out, your application terminates and is cleared from memory.

You must complete any tasks related to setting up the user interface before this method exits, but other tasks (for example, saving state) should be moved to the parallel send queue or secondary thread as needed. Since it is likely that any background tasks that you run in applicationDidEnterBackground: will not be executed until this method completes, you should request additional background execution time before starting these tasks. In other words, first call beginBackgroundTaskWithExpirationHandler: and then run the task in the send queue or secondary thread.

The application also publishes a UIApplicationDidEnterBackgroundNotification notification UIApplicationDidEnterBackgroundNotification about the same time that it calls this method to give interested objects the opportunity to respond to the transition.

+3
source

All Articles