2016-02-05 15 views
4

我一直在爲此掙扎一段時間。我試圖在人們按下彈出窗口中的「呼叫」後撥打電話。有趣的是,它直接打電話時,他們點擊電話號碼。但是,當他們點擊 '呼叫',控制檯將返回:在科爾多瓦允許撥打電話(和地圖和郵件)

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

的Config.xml:

<access origin="*"/> 
<allow-intent href="tel:*"/> 
<allow-intent href="mailto:*"/> 
<access origin="tel:*" launch-external="yes"/> 
<access origin="mailto:*" launch-external="yes"/> 

HTML:

<div ng-click="callPerson()"> {{person.phonenumber}}</div> 

使用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); 
}; 
+0

Try document.location.href ='tel:'+ $ scope.person.phonenumber; – Ved

+0

這可能會奏效!但是,我發現了一些東西;向config.xml中添加並沒有訣竅(而是)。不知道這是爲什麼。也許是因爲我嘗試從控制器調用URL? – Cake

+0

對我來說它在android中工作正常,但在iOS中沒有任何幫助? –

回答

4

可能爲時已晚,但我要評論使其他用戶無法面對這個問題。 因爲我沒有在任何地方找到任何工作解決方案。

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

我面臨同樣的問題爲郵寄地址意圖。這是工作,當我試圖直接

<a onclick="mailto:[email protected]">Email</a> 

但我得到一個錯誤,當我試圖使用javascript調用它window.location.href = 'mailto:[email protected]

internal navigation rejected - <allow-navigation> not set for url='mailto:[email protected]'

所有你需要是添加允許導航在你的config.xml中

所以你的config.xml將會是:

<access origin="mailto:*" launch-external="yes"/>  
<allow-intent href="mailto:*" /> 
<plugin name="cordova-plugin-whitelist" version="1" /> 
<allow-navigation href="mailto:*" /> 
+1

在config.xml文件中加入''可以在iOS上運行,但是在Android上打破了它的效果。非常困難。 –

+2

@DavidPrieto你應該只能在'下添加它,這樣它纔不會在Android上崩潰。 – Julien

+0

@Julien這正是我所做的,謝謝。 –

3

我使用這個配置在config.xml中 爲iOS

<allow-navigation href="tel:*" /> 

爲Android

<allow-intent href="tel:*"/> 
+0

這部分解決了我的問題,我必須將target =「_ system」添加到鏈接中 –

1

改變在​​3210 Cordova's WhiteListPlugin我沒有工作 - <access >,`。我嘗試了很多組合,包括上面的組合。這並不意味着這些將不一定工作,只是對我的設置它不。 (大廈的瀏覽器,安卓和iOS)

然而,使用Cordova InAppBrowser Plugin工作:

使用inAppBrowser插件,並設置目標_System。 cordova.InAppBrowser.open('tel:123456789', '_system');

此而過,我在iOS中看到與unsupported url的問題,並推出了原生系統的網絡瀏覽器(即不依賴於WhiteListPlugin允許URL調用)。

希望這會有所幫助。

Cordova版本6.3.1。