允许在cordova中呼叫(以及地图和邮件)

Cak*_*ake 5 ios cordova apple-maps ionic-framework

我一直在努力解决这个问题.在人们从弹出窗口按"呼叫"后,我正试图打电话.有趣的是,当他们点击电话号码时,它会直接拨打电话.但当他们点击"呼叫"时,控制台返回:

ERROR Internal navigation rejected - <allow-navigation> not set for url='tel:06-83237516

码:

控制器:

$scope.callPerson = function() {
    var link = "tel:" + $scope.person.phonenumber;
    var confirmTel = $ionicPopup.confirm({
        title: $scope.person.phonenumber,
        cancelText: 'Cancel',
        okText: 'Call'
    });
    confirmTel.then(function(res) {
        if (res) {
            window.open(link);
        } else {
            console.log('cancel call');
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

config.xml文件:

<access origin="*"/>
<allow-intent href="tel:*"/>
<allow-intent href="mailto:*"/>
<access origin="tel:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
Run Code Online (Sandbox Code Playgroud)

HTML:

<div ng-click="callPerson()"> {{person.phonenumber}}</div>  
Run Code Online (Sandbox Code Playgroud)

使用Mail,它根本不起作用,并返回相同的错误.打开地图也一样.它在PhoneGap测试应用程序中有效,但在部署时无效.

地图代码:

$scope.openmaps = function() {
    var address = $scope.person.adres + ", " + $scope.person.plaats;
    var url = '';
    if (ionic.Platform === 'iOS' || ionic.Platform === 'iPhone' || navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
        url = "http://maps.apple.com/maps?q=" + encodeURIComponent(address);
    } else if (navigator.userAgent.match(/(Android|BlackBerry|IEMobile)/)) {
        url = "geo:?q=" + encodeURIComponent(address);
    } else {
        url = "http://maps.google.com?q=" + encodeURIComponent(address);
    }
    window.open(url);
};
Run Code Online (Sandbox Code Playgroud)

Avi*_*jit 4

可能为时已晚,但我想发表评论,以便其他用户无法面对这个问题。因为我在任何地方都没有找到任何可行的解决方案。

需要 <allow-navigation href="tel:*" />在config.xml中添加

我在 mailto 意图方面面临同样的问题。我直接尝试的时候就可以了

<a onclick="mailto:test@me.com">Email</a>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用 javascript 调用它时出现错误window.location.href = 'mailto:test@me.com

internal navigation rejected - <allow-navigation> not set for url='mailto:test@me.com'

您需要做的就是在 config.xml 中添加 allowed-navigation

所以你的 config.xml 将是:

<access origin="mailto:*" launch-external="yes"/>    
<allow-intent href="mailto:*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-navigation href="mailto:*" />
Run Code Online (Sandbox Code Playgroud)

  • @DavidPrieto,您应该只能将其添加到 `&lt;platform name="ios"&gt;` 下,这样它就不会在 Android 上崩溃。 (2认同)