如何在iOS上使用tel:with*(星号,星号)或#(hash,pound)?

jpi*_*etz 26 html url-scheme phone-call ios

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

<a href="tel:123*12">Test</a>
Run Code Online (Sandbox Code Playgroud)

Mah*_*esh 33

Apple提供的这些文档应该会有所帮助:

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

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


Hus*_*sam 7

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
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)


ssc*_*ale 5

批准的答案是不正确的,至少是这样.我已经测试过两个网页和应用程序都可以使用特殊字符#*.如果您希望在任一实例中使用这些字符,那么您需要做的就是对它们进行编码.

在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)
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)