views:

589

answers:

3

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?

+1  A: 

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
awolf
A: 

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.

kidnamedlox
+1  A: 

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");
}
Biranchi