[英]Required changes for Ionic 2 call,sms and mailto functionalities in config.xml file?
[英]Ionic2 mailto: and sms:?
您好,我在使用ionic2,嘗試使用mailto:和sms打開短信和郵件應用程序,但是在Android中出現了net :: ERR_UNKNOWN_URL_SCHEME錯誤,但在ios中運行良好
我已經添加了allow-intent,access-origin和allow-navigation。 這是在我的config.xml中
<access origin="*" />
<access origin="mailto:*" launch-external="true" />
<access origin="tel:*" launch-external="true" />
<access origin="sms:*" launch-external="true" />
<access origin="geo:*" launch-external="true" />
<access origin="maps:*" launch-external="true" />
<allow-intent href="http://*/*" launch-external="true" />
<allow-intent href="https://*/*" launch-external="true" />
<allow-intent href="tel:*" launch-external="true" />
<allow-intent href="sms:*" launch-external="true" />
<allow-intent href="mailto:*" launch-external="true" />
<allow-intent href="geo:*" launch-external="true" />
<allow-navigation href="sms:*" launch-external="true" />
<allow-navigation href="mailto:*" launch-external="true" />
這是我的離子信息
Cordova CLI: 6.3.1
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.0.0-beta.20
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v6.6.0
Xcode version: Xcode 8.0 Build version 8A218a
我在我的代碼window.location.href = 'mailto:name@domain.com';
調用它window.location.href = 'mailto:name@domain.com';
謝謝你的建議
在我的應用程序中,我使用
<a [href]="sanitize('sms:' + item.sms)"><button ion-button outline><ion-icon name="ios-chatbubbles"></ion-icon></button></a>
<a href="mailto:{{item.email}}"><button ion-button outline><ion-icon name="ios-mail"></ion-icon></button></a>
請注意,我必須對短信進行清理,以使其在設備上運行,直到最后兩個版本變得不安全為止。
import { DomSanitizer } from '@angular/platform-browser';
constructor(public public navCtrl: NavController, public sanitizer: DomSanitizer) {}
sanitize(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
config.xml
<access origin="*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<allow-intent href="market:*"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
而不是window.open我使用類似這樣的方法來打開URL
<button (click)="launch('https://www.somewhere.com')">Launch URL</button>
launch(url) {
this.platform.ready().then(() => {
open(url, "_blank", "location=no");
});
}
到目前為止,對於我的應用程序,它可以在iOS和android上運行。
正如我在您的問題的評論中提到的那樣,僅使用access origin
解決您的問題,但是了解每個用戶的工作很重要。
- 訪問:控制允許進行哪些網絡請求(圖像,XHR等)(通過cordova本機掛鈎)
- 允許意圖:控制允許該應用要求系統打開的URL。 默認情況下,不允許使用外部URL
- 允許導航:控制WebView本身可以導航到的URL。 僅適用於頂層導航。
在這里閱讀更多有關這些的信息: cordova-plugin-whitelist 。 以及CSP。
很高興我能幫上忙。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.