kidnamedlox
kidnamedlox

Reputation: 826

- (void)applicationWillResignActive:(UIApplication *)application never gets called

I'm trying to handle phone calls and standby and things of that nature. I added the function

- (void)applicationWillResignActive:(UIApplication *)application

and

- (void)applicationDidBecomeActive:(UIApplication *)application

to my UIApplicationDelegate. When coming out of standby, "applicationDidBecomeActive" always gets called. However the issue is "applicationWillResignActive" never gets called.

I was wondering if anyone has run into this issue and whether or not anyone found a reason.

EDIT

More info, I discovered that my engine's update loop that gets run from applicationDidFinishLaunching was causing me to miss the message. I call

while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, .002, FALSE) == kCFRunLoopRunHandledSource);

to catch all iphone messages but it doesn't seem to catch the resignActive message before becoming inactive.

Attempting to fork a thread for my update loop is causing weird crash bugs. Anyone have any quick fix suggestions?

Upvotes: 5

Views: 10024

Answers (4)

prasannakumar
prasannakumar

Reputation: 1

- (void)applicationWillResignActive:(UIApplication *)application {
/*
 Sent when the application is about to move from active state to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
 */
}

Upvotes: -2

Biranchi
Biranchi

Reputation: 16327

Its getting called in iOS 4.0 , when the Home button is hit.

The following delegate methods are called when the Home button is hit in iOS 4.0

- (void)applicationWillResignActive:(UIApplication *)application
{
  NSLog(@"Application Did Resign Active");
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  NSLog(@"Application Did Enter Background");
}

And when you double tap the home button and again relaunch the App , the following delegate methods are called .

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  NSLog(@"Application Will Enter Foreground");
}



- (void)applicationDidBecomeActive:(UIApplication *)application
{
  NSLog(@"Application Did Become Active");
}

Upvotes: 6

kidnamedlox
kidnamedlox

Reputation: 826

Be sure to allow

- (void)applicationDidFinishLaunching:(UIApplication *)application

to return before running your game loop. One technique is to use the function

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay

on the application delegate and run your game loop after a delay of say ".01" After you do this, the message should be able to fire properly. I believe the reason for the message stomping was because the run loop was stuck on applicationDidFinishLaunching and wasn't able to push any other UIApplicationDelegate messages onto the queue.

Upvotes: 0

awolf
awolf

Reputation: 1972

I don't think

- (void)applicationWillResignActive:(UIApplication *)application

is called when a phone call is received. I think the OS waits for the user to either answer or declines the phone call. If it i declined, then the app says alive and

- (void)applicationDidBecomeActive:(UIApplication *)application

is called. If it is answered, then your app is told to exit and it will receive

- (void)applicationWillTerminate:(UIApplication *)application

Upvotes: 2

Related Questions