0

iPhone app shuts down when ever any call accepted by user. When call ends, app will resume.

I want to capture that event when app resumes after call ends. Howsoever I have tried: on App delegate: - (void)applicationWillTerminate:(UIApplication *)application - (void)applicationDidFinishLaunching:(UIApplication *)application - (void)applicationDidBecomeActive:(UIApplication *)application - (void)applicationWillResignActive:(UIApplication *)application

On view load: viewDidLoad ViewwillAppear

But non of the above event occur. Dont know how would I know that user is coming back after receiving a call.

iPhoneDev
  • 2,995
  • 4
  • 33
  • 44
  • Have you tried searching Stack Overflow, if not google? There's this: http://stackoverflow.com/questions/1742223/detect-incoming-phone-calls or a general search: http://stackoverflow.com/search?q=%5Biphone%5D+incoming+call If those methods are not being called, you either defined them incorrectly, or have them in the wrong object. – wkw Dec 01 '09 at 13:58
  • 1
    I want to capture event when app resumes after call ends. – iPhoneDev Dec 02 '09 at 09:37

2 Answers2

2

When a call is first received the app delegate is sent a applicationWillResignActive: message while the system displays the incoming call dialog.

If the user refuses the call, the app delegate receives an applicationDidBecomeActive message and the app can resume.

If user accepts the call, the app delegate receives an applicationWillTerminate message and you should prepare the app for shutting down. Then the system shuts down the app.

You can't force the system to restart your app after a call completes.

If none of these methods are being called in the delegate, the most likely explanation is that you don't have the delegate assigned properly.

It sounds like you might be confusing your app delegate with one of your view controllers. An app delegate is not expected to respond to 'viewDidLoad' an other UIViewController messages.

Edit01:

Upon second reading, it sounds like you want the app to resume the state it had prior to quitting in response to taking a phone call.

If so, your not really looking to trap an event. When an app restarts following a call, it does not receive a special event i.e. it starts just as it would if the user launched it. I think what you need to do is save the state of the application prior to shutting down and then reset to that state the next time it starts up.

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • Thanks for your answer, I want to capture that event when app resumes after call ends – iPhoneDev Dec 02 '09 at 09:35
  • You can't capture the event after the call ends, you can only capture the event of the users refusing to take a call. In that latter case, the method you want is 'applicationDidBecomeActive'. If that method is never being called then your delegate is not set properly. – TechZen Dec 02 '09 at 14:55
  • Correct, that is why I have used "weird". When call ends my app relaunch but without any single event get fired BUT if I have any timer running on viewDidLoad, it continues to run..I can write any logic in timer method to know if user coming after receiving call – iPhoneDev Dec 02 '09 at 15:55
  • NSTimers are unusual objects. They are not retained by the object that creates them but rather by the NSRunLoop of the application itself. As a result timers can remain active when other object would have disappeared. Are you saying that the timer continues to run even while the app is quit during an active phone call? – TechZen Dec 04 '09 at 19:51
0

TechZen is correct -- no special framework handling of resume after call. If you want to detect this, you need to preserve some state information at the time of app shutdown and then check for it upon application resumption.

One way to do this is to use a flag that is set in applicationWillResignActive (e.g., bIncomingEventInterrupt = YES) and applicationDidResignActive (bIncomingEventInterrupt=NO) and applicationDidBecomeActive (bIncomingEventInterrupt=NO). Then in applicationWillTerminate check the state of this flag.

If there's been an incoming call, the flag will have been set true. If the user accepts the call, the app will shutdown with the flag=YES, and you should persist some property list, etc that contains information that you check for when the app starts up (applicationDidFinishLaunching). If the user declines the call, the flag will be reset false and the application should then invoke some default non-persist code during shutdown. You can/should clean up the persisted data either in the didFinishLaunching or in the willTerminate "non-persist" branch.

jstevenco
  • 2,913
  • 2
  • 25
  • 36