PruitIgoe
PruitIgoe

Reputation: 6384

iOS Application Does Not Run In Background = YES - how do I check when the user exits app

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.

Upvotes: 0

Views: 1432

Answers (2)

Greg Price
Greg Price

Reputation: 2556

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.

Upvotes: 1

Thilina Chamath Hewagama
Thilina Chamath Hewagama

Reputation: 9040

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

Upvotes: 0

Related Questions