简体   繁体   English

Ionic2 mailto:和短信:?

[英]Ionic2 mailto: and sms:?

Hi there I'm using ionic2, try to open sms and mail app with mailto: and sms: but got error net::ERR_UNKNOWN_URL_SCHEME in android, but running well in ios 您好,我在使用ionic2,尝试使用mailto:和sms打开短信和邮件应用程序,但是在Android中出现了net :: ERR_UNKNOWN_URL_SCHEME错误,但在ios中运行良好

I already add allow-intent, access-origin and allow-navigation. 我已经添加了allow-intent,access-origin和allow-navigation。 This is in my config.xml 这是在我的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" />

This is my ionic info 这是我的离子信息

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

I call this in my code window.location.href = 'mailto:name@domain.com'; 我在我的代码window.location.href = 'mailto:name@domain.com';调用它window.location.href = 'mailto:name@domain.com';

Thank you in advice 谢谢你的建议

In my App I use 在我的应用程序中,我使用

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

Note I had to Sanitize the sms to make it work on devices as of about the last two releases it becomes Unsafe. 请注意,我必须对短信进行清理,以使其在设备上运行,直到最后两个版本变得不安全为止。

import { DomSanitizer } from '@angular/platform-browser';

constructor(public public navCtrl: NavController, public sanitizer: DomSanitizer) {}

sanitize(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}

config.xml 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>

Instead of window.open I use something like this to open URLs 而不是window.open我使用类似这样的方法来打开URL

<button (click)="launch('https://www.somewhere.com')">Launch URL</button>

launch(url) {
    this.platform.ready().then(() => {
        open(url, "_blank", "location=no");
    });
}

So far it works on both iOS and android for my App. 到目前为止,对于我的应用程序,它可以在iOS和android上运行。

As I mentioned in the comment of your question, just using access origin solved your problem but It's important to know what each one does. 正如我在您的问题的评论中提到的那样,仅使用access origin解决您的问题,但是了解每个用户的工作很重要。

  1. Access: Controls which network requests (images, XHRs, etc) are allowed to be made (via cordova native hooks 访问:控制允许进行哪些网络请求(图像,XHR等)(通过cordova本机挂钩)
  2. Allow-intent: Controls which URLs the app is allowed to ask the system to open. 允许意图:控制允许该应用要求系统打开的URL。 By default, no external URLs are allowed 默认情况下,不允许使用外部URL
  3. Allow-navigation: Controls which URLs the WebView itself can be navigated to. 允许导航:控制WebView本身可以导航到的URL。 Applies to top-level navigations only. 仅适用于顶层导航。

Read up more on these here: cordova-plugin-whitelist . 在这里阅读更多有关这些的信息: cordova-plugin-whitelist As well as CSP. 以及CSP。

Glad I could help. 很高兴我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM