gpt4 book ai didi

ios - 使用 openURL 的 '#' 结尾

转载 作者:行者123 更新时间:2023-11-28 12:28:17 25 4
gpt4 key购买 nike

let x = dpadtxt.text! + "#"
let url = URL(string: ("tel://23456712561,2#,\(x)"))!
UIApplication.shared.openURL(url)

当我在字符串末尾添加 # 时,会出现以下错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

最佳答案

查看 Apple URL Scheme 引用 documentation,您可以在其中阅读有关如何使用电话号码编码的信息。

在该文档中,您可以阅读...

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. If your app receives URL strings from the user or an unknown source, you should also make sure that any special characters that might not be appropriate in a URL are escaped properly. For native apps, use the stringByAddingPercentEscapesUsingEncoding: method of NSString to escape characters, which returns a properly escaped version of your original string.

你必须用这样的东西对你的数字 String 进行编码

let phone: NSString =  "tel://23456712561,2#,#"

if let phone = phone.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
{
print(phone)
}

请检查我的 NSCharacterSet 是否正确,因为我现在无法在设备上测试它。

关于ios - 使用 openURL 的 '#' 结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42779885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com