ios 科尔多瓦试图拨打电话号码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19639663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:38:54  来源:igfitidea点击:

Cordova trying to dial telephone number

iosobjective-cxcodecordova

提问by Mike

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

我正在尝试在 iOS 中拨打电话号码,但是我只有模拟器和 iPod Touch 可以测试。

The code uses something along the lines of:

该代码使用了以下内容:

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

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

在 Android 上运行良好,但在 iOS 中它会因:

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

无法加载网页,错误:无法显示 URL

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 PhoneDialerand 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.

现在,我确实意识到以前有人问过这个问题,但前一段时间的普遍共识是“它不起作用,你需要使用插件”。一段时间以来,关于此的问题并不多,并且似乎有什么问题表明它在以编程方式执行时有效(如上面的window.location.href)。我已经尝试过iOS PhoneDialer和同一插件的较新版本,但两者在 XCode ( ARC forbids explicit message send of 'release') 中都有错误- 有点麻烦,我可以运行它,但是 PhoneGap 没有找到该插件 - 感觉就像我正在用这种方法撞到砖墙,我无法相信这么简单的事情需要如此过度的东西。

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?

我知道出于安全原因你不能自动拨号/自动呼叫一个号码,但我需要做的就是打开预先填充号码的拨号器,这肯定mailto:[email protected]与用发件人预先打开你的电子邮件客户端的链接没有什么不同人口稠密?

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? :)
  • 最近更新 PhoneGap、iOS 或 XCode 时,这种情况是否有所改变?
  • 或者,是不是我不能在 iPod 或模拟器上执行此操作,但它可以在 iPhone 上正常工作?
  • 我该如何解决?:)

回答by gaqzi

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

您没有指定您使用的是哪个版本的 Cordova,所以我假设版本 > 3。

Make sure that InAppBrowser, a pluginsince version 3, is installedand then open the link by calling it through Javascript like this:

确保安装了自版本 3 以来的插件InAppBrowser,然后通过像这样通过 Javascript 调用它来打开链接:

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

_systemwill 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.

_system将使用系统自己的浏览器打开它,然后将打开呼叫对话框,如果您针对http://maps.apple.com/使用它,它将在地图应用程序中打开,其他应用程序也类似,这些应用程序为特殊网址打开。

Remarks:

评论:

  • As described in the docs of the InAppBrowser pluginthe window.openfunction 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 numis a string.
  • InAppBrowser 插件文档中所述,window.open功能不会自动设置。你必须做你自己:window.open = cordova.InAppBrowser.open;。相反,您可以直接使用cordova.InAppBrowser.open('tel:12345678', '_system');
  • 确保您的号码中没有任何空格(+ 前缀是可以的)。例如,您可以使用如下函数,假设num是一个字符串。

Function:

功能:

function placeCall(num) {
    if (window.cordova) {
        cordova.InAppBrowser.open('tel:' + num.replace(/\s/g,''), '_system');
    }
}

回答by vivek khurana

Below Code works perfectly fine for iphone:-

下面的代码适用于 iphone:-

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

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

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

模拟器不支持拨号器。没必要浪费时间。

回答by Matty J

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.

确保您的 href 中的电话号码也没有任何格式,因为在 iOS 上它会导致链接在 PhoneGap 应用程序中不起作用。因此,例如,使用 tel:0390005555,而不是 tel:(03) 9000 5555。

回答by Peter Cetinski

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.

我不相信这是科尔多瓦问题。我知道在原生 iOS 中,您无法在模拟器或 iPod touch 上调出拨号器。您需要在实际的 iPhone 上对此进行测试。

回答by Sajith Sankaranarayanan

I know this is a late answer time.

我知道这是一个迟到的回答时间。

Try by adding //to the url. Like this tel://xxxxxxxxxand see if it works.

尝试通过添加//到 url。像这样tel://xxxxxxxxx,看看它是否有效。

Worked for me in IOS 8.4, iPhone 6, 6+ as of today.

截至今天,我在 IOS 8.4、iPhone 6、6+ 中为我工作。