我在电话中使用#时遇到问题,在控制台中它显示(tel://*155*222222*123%23)
,我相信问题是使用#。我查过了,有人说不允许在电话中使用特殊字符。
var code = String()
var ID = String()
var Card = String()
@IBAction func ChargePhone(_ sender: Any) {
ID = "123"
ID = ID.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
Card = "222222"
code = "*155*"
var RESULT = "(code)(Card)*(ID)#"
RESULT = RESULT.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
if let url = URL(string: "tel://(RESULT)"), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
电话应用程序不允许在 iOS 上的电话号码重定向中使用特殊字符。
参考:https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html