Determine if UIViewController is closing due to application exiting?

Is there a way to check in the viewWillDisappear if it is called because the application exits due to the usual ways to dismiss it? The applicationWillTerminate method in the application delegate is called after the current view is closed. I want to do different things depending on whether it is being rejected due to IBAction or the user pressing the menu button.

Thank!

+2


source to share


2 answers


You have to use UIApplicationWillTerminateNotification

in your controller, set the flag, and then check the flag in the implementation viewWillDisappear

.



NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self       
                  selector:@selector(applicationWillTerminate:)
                      name:UIApplicationWillTerminateNotification
                    object:nil];

      

+3


source


I haven't used it for your purposes yet, but the UIApplicationWillResignActiveNotification may appear before the applicationWillTerminate is called .

Just throw it ...



[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResign:) name:UIApplicationWillResignActiveNotification object:NULL];

      

... to your UIViewController to test it.

+1


source







All Articles