views:

602

answers:

2

I need to determine when an incoming phone call arrives. I know that applicationWillTerminate will be called if the user takes the call and applicationWillResignActive when the popup with the confirmation message for the call appears, however:
-applicationWillTerminate is also called when the app exits by user request or battery is about to die
-applicationWillResignActive is also called when a UIViewAlert is shown.

Thanks

+1  A: 

In short - no, you can not determine if there's an incoming call or another kind of interruption in your application.

Vladimir
I was afraid of that. Thanks anyways.
MihaiD
A: 

I found this article on handling incoming calls; terminating resuming and persisting state,.

It might help you..

http://www.tomwhitson.co.uk/blog/2009/04/handling-interuptions-to-your-app/

(void)applicationWillResignActive:(UIApplication *)application{ //our app is going to loose focus since thier is an incoming call [self pauseGame]; }

(void)applicationDidBecomeActive:(UIApplication *)application{ //the user declined the call and is returning to our app [self resumeGame]; }

(void)applicationWillTerminate:(UIApplication*)application{ //the user answered the call (or quit the app) so save the //game as we are shutting down [self saveGameState]; }

hearn
This is useful for many scenarios but you cannot be 100% certain applicationWillResignActive is called as a result of an incoming phone call.
MihaiD