0

In my info.plist file I have Application Does Not Run In Background = YES. This is an enterprise app and I am trying to log when a user exits (hits the home button). But in AppDelegate, I was logging to the console to see what method would be called and none of them were (applicationWillResignActive, applicationDidEnterBackground, applicationWillTerminate). Is there a way to determine when a user exits with the plist setting I have>?

Thanks

Here's the willTerminate method, it's right out of the box:

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"goodbye");
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.



}

I've changed the plist settings and can now log from applicationDidEnterBackground.

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
  • possible duplicate of [applicationWillTerminate when is it called and when not](http://stackoverflow.com/questions/7818045/applicationwillterminate-when-is-it-called-and-when-not) – KevinDTimm Feb 28 '13 at 19:11

2 Answers2

1

So you don't want the app to run in the background but you want to know when the app terminates? Do this

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

Then fill in your own applicationWillTerminate method. You won't have much time to do stuff.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Greg Price
  • 2,556
  • 1
  • 24
  • 33
  • There is no need for this. The app delegate already has its applicationWillTerminate method that is called in this case. – rmaddy Feb 28 '13 at 19:11
0

if you have set ApplicationDoesNotRunInBackgound to YES, then this must work,

put this method in your appDelegate.m

-(void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"user exits app");
}

In my app, with the same plist settings, this method fires

Thilina Chamath Hewagama
  • 9,039
  • 3
  • 32
  • 45