Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova trying to dial telephone number

I am trying to dial a phone number in iOS, however I only have the simulator and an iPod Touch to test on.

The code uses something along the lines of:

window.location.href = 'tel:01234567890';

Working fine with Android, but in iOS it dies with:

Failed to load webpage with error: The URL can't be shown

Now, I do realise this has been asked before, but the general consensus from some time ago was "It doesn't work, you'll need to use a plugin". There haven't been many questions on this for some time though, and what questions there are seem to suggest it works when doing it programmatically (as above with window.location.href). I have tried the iOS PhoneDialer and the newer version of the same plugin, but both have errors in XCode (ARC forbids explicit message send of 'release') - a bit of faffing and I can get this running, but then PhoneGap doesn't find the plugin - it really feels like I'm hitting a brick wall with this method, and I can't believe something as simple as this requires something so over the top.

I know you cannot auto-dial/auto-call a number for security reasons, but all I need to do is open the dialer with number pre-populated, which is surely no different to a mailto:[email protected] link opening your email client with the sender pre-populated?

So, my questions are:

  • Has this changed with a recent update to PhoneGap, iOS or XCode?
  • Or, is it a case that I cannot do this on an iPod or Simulator, and it will work fine on an iPhone?
  • How can I fix it? :)
like image 422
Mike Avatar asked Oct 28 '13 16:10

Mike


4 Answers

You didn't specify which version of Cordova you are using so I'm going to assume version > 3.

Make sure that InAppBrowser, a plugin since version 3, is installed and then open the link by calling it through Javascript like this:

window.open('tel:12345678', '_system')

_system will open it with the systems own browser which in turn will open the call dialog, if you use it against http://maps.apple.com/ it will open in the maps app and similar for other apps which opens for special urls.

Remarks:

  • As described in the docs of the InAppBrowser plugin the window.open function won't be set automatically. You have to do it your self: window.open = cordova.InAppBrowser.open;. Instead you can directly use cordova.InAppBrowser.open('tel:12345678', '_system');
  • Make sure your number doesn't have any blankspaces in it (the + prefix is okay). For example you could use a function like the following, assuming num is a string.

Function:

function placeCall(num) {
    if (window.cordova) {
        cordova.InAppBrowser.open('tel:' + num.replace(/\s/g,''), '_system');
    }
}
like image 129
gaqzi Avatar answered Sep 28 '22 09:09

gaqzi


Below Code works perfectly fine for iphone:-

window.open('tel:123456', '_system');

Simulator doesn't support dialer. No need to waste time.

like image 44
vivek khurana Avatar answered Sep 28 '22 07:09

vivek khurana


Make sure that the phone number in your href also doesn't have any formatting in it, as on iOS it causes the link not to work in a PhoneGap App. So for example, use tel:0390005555, and not tel:(03) 9000 5555.

like image 22
Matty J Avatar answered Sep 28 '22 08:09

Matty J


I don't believe this is a Cordova issue. I know in native iOS you cannot bring up the dialer on the simulator or on an iPod touch. You will need to test this on an actual iPhone.

like image 24
Peter Cetinski Avatar answered Sep 28 '22 09:09

Peter Cetinski