Cordova试图拨电话号码 [英] Cordova trying to dial telephone number

查看:144
本文介绍了Cordova试图拨电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS中拨打电话号码,但我只有模拟器和iPod Touch进行测试。



的:

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

在Android中运行正常,但在iOS中它死了:


无法加载网页时出错:无法显示网址


现在,我意识到这已被问过,但从一些时间以前的一般共识是它不工作,你需要使用一个插件。在这一段时间没有很多问题,有一些时间,什么问题似乎似乎建议它在编程方式(如上所述 window.location.href )。我尝试了 iOS PhoneDialer 和同一插件的较新版本,但两者都在XCode( ARC禁止显式消息发送'释放') - 一点faffing,我可以得到这个运行,但PhoneGap没有找到插件 - 它真的感觉像我'用这种方法打砖墙,我不敢相信这么简单,因为这需要在顶部。



我知道你不能自动拨号/为了安全起见,自动呼叫一个号码,但我所需要做的是打开拨号器预先填充的数字,这肯定没有区别 mailto:info@example.com 链接打开您的电子邮件客户端与发件人预填充?



所以,我的问题是:




  • 到PhoneGap,iOS或XCode?
  • 或者,这是一种情况,我不能在iPod或模拟器上做这个,它可以在iPhone上正常工作?

  • 我如何解决它? :)
  • 您没有指定您使用的Cordova版本,因此我' m将假设版本> 3。



    确保 InAppBrowser plugin 从版本3开始, ,然后通过JavaScript调用它来打开链接,如下所示:

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

    _system 会使用系统自己的浏览器打开它,而浏览器会打开调用对话框,如果您使用它对 http:/ /maps.apple.com/ 会在地图应用程式和类似应用程式中开启,并开启特殊网址。



    备注:




    • 在InAppBrowser插件的文档中, window.open 函数不会被自动设置。你必须自己做: window.open = cordova.InAppBrowser.open; 。您可以直接使用 cordova.InAppBrowser.open('tel:12345678','_system');

    • 没有任何空格(+
      前缀是好的)。例如,你可以使用如下的函数
      假设 num 是一个字符串。



    功能:

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


    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:info@example.com 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? :)

    解决方案

    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');
        }
    }
    

    这篇关于Cordova试图拨电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆