ios - 带有字符串 tel ://*#06# is returning nil in Swift 的 URL

标签 ios swift

我在 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/

相关文章:

iphone - iOS如何停止 View 旋转

swift - 如何在SpriteKit中将物体放在不同的Z层上

ios - MPMediaQuery.artistsQuery() 以组形式显示

ios - Xcode 6 - 将导航 Controller 添加到 Storyboard,但未出现在应用程序中

ios - 注释 PDF : where to begin?

ios - 如何停止 MPMoviePlayerViewController 在 moviePlaybackDidFinish 上的自动关闭?

ios - 通过 App Delegate 从 UINavigationController 呈现 UIViewController

ios - Tesseract OCR 无法识别从设备拍摄的图像

java - java代码对应的swift中的web服务请求

ios - 是否有必要在 swift iOS 中使用扩展来定义委托(delegate)方法