Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a UIViewController method that gets automatically called when the app moves to the background?

Tags:

ios

My UIViewController registers for notifications which my model component sends out when it has finished downloading content.

The downloading can occur in the background (by using beginBackgroundTaskWithExpirationHandler:) so obviously I don't want my GUI to attempt to redraw etc. if the download completes in the background.

So I guess I have two choices - 1) the model knows when its in the background/foreground and doesn't fire the notifications. 2) the UIViewController deregisters for notifications when its in the background.

Option 2) is preferable.

Is there a method on UIViewController that is always called when the app goes into the background? Or will the UIViewController have to register to receive a notification event when the app moves into the background?

(Seems like viewWillDisappear, viewWillUnload etc. don't get called when the app moves to the background?)

like image 693
Gruntcakes Avatar asked Mar 05 '12 18:03

Gruntcakes


People also ask

What is UI view controller?

A UIViewController is an object which manages the view hierarchy of the UIKit application. The UIViewController defines the shared behavior and properties for all types of ViewController that are used in the iOS application. The UIViewController class inherits the UIResponder class. ADVERTISEMENT.

What is view controller in iOS?

A view controller acts as an intermediary between the views it manages and the data of your app. The methods and properties of the UIViewController class let you manage the visual presentation of your app. When you subclass UIViewController , you add any variables you need to manage your data in your subclass.

What is a controller in Swift?

A view controller typically manages a single User Interface (UI) or “screen” in your app. It also manages interactions between the UI and the underlying data, better known as models.


1 Answers

make your view controller register for UIApplicationDidEnterBackgroundNotification in view did load... the selector method associated will be called before entering background..

like image 194
Shubhank Avatar answered Oct 04 '22 04:10

Shubhank