Weird functioning of Application event in iPhone
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)appl开发者_JAVA技巧icationDidBecomeActive:(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.
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 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.
精彩评论