iOS 4.2 - Return to app after phone call
I can successfully initiate a phone call within my app using the following:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];
However, is it possible to automatically return back to the app once the phone call has been terminated? It seems this was not possible under iPhone OS 3.0 but I am hoping it is now possible under iOS 4.2 with multitasking (I wasn't able to find any information on this question specific to iOS 4.2).
Thanks in advance for any assistance!
Solution 1:
I know the question is very old, but currently you can do this (at least on iOS 5) by using telprompt://, like:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://123456789"]];
iPhone will show alert view confirmation and when call ends, your app shows again, instead of iPhone's call app.
Solution 2:
As far as I'm aware, because control is passed to the phone.app to make the call, once the call has ended, as far as iOS is concerned phone.app is the current app so that stays in the foreground.
There doesn't seem to be anything you can do about this at the moment. It might be worth putting in a feature request to allow for a "modal phone call" similar to MFMessageComposer
that allows you to send emails/sms within your own app.
EDIT
You can follow the advice that Frin gives in the answer below as this contains more up to date information.
Solution 3:
I believe the issue is that you're still making the sharedApplication call and as per the other thread, there is no need to add the web view as part of your hierarchy.
I took your code, modified it as below, and it works just fine:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
// The WebView needs to be retained otherwise it won't work.
if (!mCallWebview)
mCallWebview = [[UIWebView alloc] init];
[mCallWebview loadRequest:[NSURLRequest requestWithURL:phoneURL]];
Following the call your own app runs as before.
Solution 4:
This is definitively possible since the introduction of iOS 4.0. The best way to handle this is to use a UIWebView, load the "tel:0123456" URL in the WebView without adding it to the view hierarchy. The iOS will automatically display an alert with the phone number and ask the user to confirm by pressing "Call".
Once the call is completed, your app will be brought back to foreground automatically. This is detailed in this other thread: Return to app behavior after phone call different in native code than UIWebView