我在 Swift 4.x 中使用以下代码:
let url = URL(string: "tel://*#06#")
这使得 url 为零。只是这个特定的数字有一些问题。有人可以告诉我如何解决这个问题以及为什么这首先是一个问题。
最佳答案
根据苹果文档here :
To prevent users from maliciously redirecting phone calls or changing the behavior of a phone or account, the Phone app supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone app does not attempt to dial the corresponding phone number.
请注意,对于其他字符,您可以使用 addingPercentEncoding
方法来转义特殊字符,该方法会返回原始字符串的正确转义版本。
示例:
let encoding = phoneNumberString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
关于ios - 带有字符串 tel ://*#06# is returning nil in Swift 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53116541/