Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIApplicationDidEnterBackgroundNotification

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

like image 774
Manish Jain Avatar asked Feb 01 '11 12:02

Manish Jain


People also ask

What is UIApplication in Swift?

Swift version: 5.6. Subclassing UIApplication allows you to override functionality such as opening URLs or changing your icon, but it's a non-trivial task in Swift because of the @UIApplicationMain attribute. If you look in your AppDelegate.

When Applicationwillenterforeground is called?

Tells the delegate that the app is about to enter the foreground.

How to know when app goes to background swift?

There are two ways to be notified when your app moves to the background: implement the applicationWillResignActive() method in your app delegate, or register for the UIApplication. willResignActiveNotification notification anywhere in your app.

What is Nsnotification name?

A structure that defines the name of a notification.


1 Answers

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.

like image 169
Oded Ben Dov Avatar answered Sep 28 '22 05:09

Oded Ben Dov