【问题标题】:How to Dial USSD with ionic framework如何使用离子框架拨打 USSD
【发布时间】:2016-12-14 20:26:36
【问题描述】:

我正在使用 ionic 框架制作一个混合应用程序,并且想拨打 USSD。拨打普通号码(12345678)没有问题;但我无法拨打 USSD (*556#);即使在编码“#”字符之后。有人可以帮帮我吗?

<a ion-button href="tel:556" >call</a> // This dials the number - no problem here 
<a ion-button href="tel:*556#" >Call</a> // This does nothing <a ion-button href="tel:encodeURIComponent(*556#)" >Call</a> // This doesn't work either 

它拨打的是 USSD,但我只是不认为它拨打 *556#"Error Performing Request, Unknown Error" 出现在我的屏幕上。当我登录encodeURIComponent(*556#) 时,我看到了*556%23

【问题讨论】:

  • 请向我们展示您的代码,您尝试了什么?
  • 我尝试了以下方法:` call // This dials the number - no problem here Call // This does nothing Call` // 这也不起作用 - 它拨打 USSD 但我不这样做因为“执行请求时出错,未知错误”出现在我的屏幕上,所以它不会准确地拨打 *556#。当我记录 encodeURIComponent(*556#) 时,我看到 *556%23。 @Ivaro18
  • 编辑问题并将格式化代码放入其中,而不是在 cmets 中
  • 另外,请参阅此答案forum.ionicframework.com/t/…
  • @Marko ,访问了您发送的链接...我的正常通话正常。不起作用的是拨打 U​​SSD。只要号码前有'*',如(*556#)号码不拨。

标签: ios ionic-framework ionic2


【解决方案1】:

首先,让我告诉您,有些模拟器在某些设备上运行起来很有趣。我有客户遇到过一些问题,代码运行良好,但模拟器有问题。

我用过并且没有任何问题的模拟器是 genymotion for android。

来到你的代码,假设我们需要拨打号码123#456这是你需要在你的html中拥有的

 <a href="tel:+123%23456" class="button button-positive">Call me 1</a>
 <button (click)="callIT('1-23#456')">call function</button>

注意这里我展示了两种方法,一种是href,另一种是click

如您所见,第一个可以开箱即用,因为我们已在 href 属性中将 # 替换为 %23

在第二种方式中,我们使用了一个名为callIT 的函数并将数字传递给它。

所以在你的 Javascript 代码中,函数如下

callIT(passedNumber){
    passedNumber = encodeURIComponent(passedNumber);
 window.location = "tel:"+passedNumber;
}

如图所示,我们使用的是encodeURIComponent

正如您在代码中提到的那样,在 href 属性中使用 encodeURIComponent 将不起作用,因为它将被视为字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 2016-11-12
    相关资源
    最近更新 更多