3

I have used the following code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", self.phoneNumber]]];

After the phone call, the dialer goes to the Phone App, instead of back to my app.

Any ideas?

iOS 7. Xcode 5.

Kara
  • 6,115
  • 16
  • 50
  • 57
Jake Chasan
  • 6,290
  • 9
  • 44
  • 90

1 Answers1

12

You can make the same sort of call but replace tel:// with telprompt:// so it will look like:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", self.phoneNumber]]];

This will return you to the app once you have finished your phone call. This will work across most if not all iOS versions.

EDIT - 14/07/2015

I have been informed in the comments below that using telprompt:// is actually unsupported by Apple so they could decide to change this anytime and it could affect your app. So my suggest would be to wrap this call in a canOpenURL: and see if you can open the URL before hand and handle it if you can't.

I'd probably actually go with checking this at App load up and setting it to a global variable that you can check when constructing your UI and maybe just not offer that functionality at all if you can't do it which would create a better user experience.

Big thanks to NicolasMiari for pointing out the error and supplying the link to iOS: return to app when the call fails

Community
  • 1
  • 1
Popeye
  • 11,839
  • 9
  • 58
  • 91
  • Is there any way to disable the alert which pops up? – Jake Chasan Dec 22 '13 at 17:41
  • Don't believe so because at that point you have actually left the app. – Popeye Dec 22 '13 at 17:42
  • @Downvoter please detail the reason for the downvote as this is correct. – Popeye Dec 23 '13 at 10:58
  • But it need to click the call to continue. – Bagusflyer Dec 01 '14 at 02:59
  • @bagusflyer What???? Obviously they will need to click to continue, so what's your point? – Popeye Dec 01 '14 at 08:22
  • I am trying this solution on an iPhone 4s running iOS 7.0.4. The phone does not have a SIM card, so the call always fails. When I tap "Cancel" after failure, I am **not** taken back to the app, but to the home screen (springboard). – Nicolas Miari Jul 14 '15 at 08:28
  • @NicolasMiari Ok this sounds like a new question to me. – Popeye Jul 14 '15 at 08:29
  • @Popeye Yes, and indeed it is answered here: http://stackoverflow.com/a/18759426/433373 (just found it). – Nicolas Miari Jul 14 '15 at 08:31
  • @NicolasMiari I was unaware that it wasn't an official method however I don't see why it isn't it seems perfectly reasonable that users would want to return to the app after a phone call and would make a good user experience. – Popeye Jul 14 '15 at 08:33
  • Perhaps the safest, most future-proof solution would be to attempt an initial `openURL:` with the `telprompt://` scheme, and on failure fallback to a second try, this time with `tel://`. – Nicolas Miari Jul 14 '15 at 08:35
  • Yes I would always wrap anything that attempts to open a url in a `canOpenURL:` before hand. Actually I'd do the check on app load up and then have that value throughout the app so I could hide that functionality from the user if need be. – Popeye Jul 14 '15 at 08:37
  • 1
    @NicolasMiari I have updated my answer with information based on this conversation and credited you for pointing out the error with `telprompt://` – Popeye Jul 14 '15 at 08:57
  • @Popeye you have a typo in my (real) name ;) – Nicolas Miari Jul 14 '15 at 08:59