33

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!

2
  • Doesn't it do that by default?
    – BoltClock
    Feb 17, 2011 at 11:35
  • note that in 2017 onwards, it just does this by default, regarding the telephone. simply call UIApplication.shared.open and you're all set
    – Fattie
    Mar 27, 2017 at 15:13

6 Answers 6

121

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.

7
  • 1
    This is actually the right answer, but it was posted a year after the question, so it wasn't available at the time. Use this!
    – Gup3rSuR4c
    Aug 2, 2012 at 22:33
  • 3
    I second this; please do use this answer! - Would it be worth editing my answer to display this info (giving credit to Frin, of course)?
    – Luke
    Sep 24, 2012 at 18:10
  • Does this call require some greater context? I'm calling this line from an IBAction connected to a tap gesture recognizer and I can't get it to fire (or even log anything).
    – ele
    May 8, 2013 at 17:00
  • 1
    @ele: this call won't do anything on simulator or iPad, it requires calling functionality on hardware.
    – frin
    Sep 13, 2013 at 9:48
  • @frin Thanks. That's probably where I was running it.
    – ele
    Sep 14, 2013 at 17:51
7

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.

0
6

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.

3

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

5
  • Does this still work with iOS 5? The calls are all working, however nothing happens, phone doesn't open, app just continues.
    – mservidio
    Jan 30, 2012 at 2:44
  • Yes, I'm using it in an app we are currently developing. It does not work in the iPhone Simulator for some reason, but on a real phone opening a NSURL containing "tel:..." produces an Alert dialog that ask the user to confirm the call; if the user presses "Call" the "Phone" app is brought forward, the call is established. Once the call is complete, the Phone app is pushed to background and your app is restored to foreground.
    – ekscrypto
    Jan 31, 2012 at 18:46
  • Hm, I was trying with a physical phone. I'll try again later today, though it didn't work for me before. Does the url string have to be special, or does "tel:8001234567" format work? Here's what I was trying: UIWebView *callWebview = [[UIWebView alloc] init]; [self.view addSubview:callWebview]; NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", result.phoneNumber]]; if([[UIApplication sharedApplication] canOpenURL:telURL]) { [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; }
    – mservidio
    Jan 31, 2012 at 19:10
  • The code doesn't throw any exceptions for me, the canOpenURL method returns true, and then loadRequest is called, but it doesn't do anything.
    – mservidio
    Jan 31, 2012 at 19:10
  • Here's how I do it in my app: UIWebView *ddiCallWebView; NSURL *ddiUrl = [NSURL URLWithString:[@"tel://" stringByAppendingString:ddi]]; if( !ddiCallWebView ) { ddiCallWebView = [[UIWebView alloc] init]; } [ddiCallWebView loadRequest:[NSURLRequest requestWithURL:ddiUrl]];
    – ekscrypto
    Apr 10, 2012 at 12:59
2

I have given this answer in iPhone SDK: Launching an app after call ends I will also post my code here.. here you can make a call without closing you app..

-(IBAction) dialNumber:(id)sender{

NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
 NSURL  *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];

if ([osVersion floatValue] >= 3.1) { 
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
[webview loadRequest:[NSURLRequest requestWithURL:url]]; 
webview.hidden = YES; 
// Assume we are in a view controller and have access to self.view 
[self.view addSubview:webview]; 
[webview release]; 
} else { 
// On 3.0 and below, dial as usual 
[[UIApplication sharedApplication] openURL: url];
}


}
1
  • Thanks, m8! Good job.
    – Felipe
    Oct 27, 2015 at 19:29
0

With iOS 9.3.4, every technique that I try has control return to the calling app after the phone call. Has this behavior changed recently? This example is just a Swift and simplified version of https://github.com/jatraiz/RZTelpromptExample:

class ViewController: UIViewController {

    let phoneNumber = "7204790465"

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    @IBAction func callWithTelPushed(sender: AnyObject) {
        if let url = NSURL(string: "tel:" + self.phoneNumber) {
            UIApplication.sharedApplication().openURL(url)
        }
    }

    @IBAction func callWithTelpromptPushed(sender: AnyObject) {
        if let url = NSURL(string: "telprompt:" + self.phoneNumber) {
            UIApplication.sharedApplication().openURL(url)
        }
    }

    @IBAction func callWithRZTelpromptPushed(sender: AnyObject) {
        RZTelprompt.callWithString(self.phoneNumber)
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.