【问题标题】:How to use tel: with * (star, asterisk) or # (hash, pound) on iOS?如何在 iOS 上使用 tel: with * (star, asterisk) 或 # (hash, pound)?
【发布时间】:2011-06-07 08:27:38
【问题描述】:

我正在尝试使用带有 * 的 tel 网址在 iPhone 上发起呼叫。它会正确调出通话对话框,但在您单击通话时会返回到 safari。

<a href="tel:123*12">Test</a>

【问题讨论】:

    标签: html ios url-scheme phone-call


    【解决方案1】:

    This documentation from Apple 应该会有所帮助:

    为防止用户恶意重定向电话或更改电话或帐户的行为,电话应用程序 支持电话中的大多数(但不是全部)特殊字符 方案。具体来说,如果 URL 包含 * 或 # 字符,则 电话应用程序不会尝试拨打相应的电话 号码。

    更新(2018 年 1 月 2 日):此处提及的信息可能已过时。如果 Apple 在其较新的 SDK 中放宽了这些规则,请参阅新文档。请参阅 Husam 的回答。

    【讨论】:

    【解决方案2】:

    iOS11现在允许我们使用*#拨打号码


    Swift 示例代码

        let number = "*111*12345#"
        let app = UIApplication.shared
        if let encoded = number.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) {
            let u = "tel://\(encoded)"
            if let url = URL(string:u) {
                if app.canOpenURL(url) {
                    app.open(url, options: [:], completionHandler: { (finished) in
    
                    })
                    return
                }
            }
        }
    

    【讨论】:

    • 怎么样?使用 iOS11、Xcode 9.2、Swift 4.0.3,我无法拨打带有 # 和 * 的号码。
    • 谢谢,胡萨姆!我正在编码整个字符串(tel://*111*12345#)。关键是编码数字,而不是tel://前缀。
    【解决方案3】:

    批准的答案不正确,至少现在不再正确。我已经测试了web page 和在应用程序中能够使用特殊字符#* 进行拨号。如果您希望在任一实例中使用这些字符,您必须做的就是对它们进行编码。

    在 HTML 中,# 变为 %23* 不需要转义

    如果使用 Swift,您可以使用此功能对链接进行编码并从应用程序中按下它:

    //number format example (commas are pauses): 123-456-7890,,555#,1234
    fileprivate func callNumber(_ number: String) {
        let dialString = "telprompt://" + number
        if let escapedDialString = dialString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) {
          if let dialURL = URL(string: escapedDialString) {
            UIApplication.shared.openURL(dialURL)
          }
        }
      }
    

    【讨论】:

    • 我们可以从我的应用程序中打开拨号盘吗?像 *123456# 这样的字符串。我已经尝试过上述答案,但它不起作用。请帮帮我,非常紧急。
    • @Husam's answer。 Husam 的示例代码确实适用于 iOS 11。诀窍是编码数字部分,而不是 tel:// 部分。 (也不是说不再需要 telprompt:// 来获得呼叫确认提示。tel:// 现在也会这样做。)
    • 我认为你只需要 .open() 而不是 .openURL
    【解决方案4】:

    如果您想将 * 添加到类型为“tel”的 href,您需要使用 utf-8 编码版本 - %2A

    参考:W3

    例如

    &lt;a href="tel:%2A1234"&gt; Phone me &lt;a/&gt;

    【讨论】:

      猜你喜欢
      • 2011-04-04
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多