gpt4 book ai didi

ios - 如何在没有 ( ) 或 - swift 3 的情况下删除电话号码?

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:16 24 4
gpt4 key购买 nike

我遇到了一个问题,我需要在没有 ()- 的情况下去除我的表格 View 单元格上的 phoneNumber 所以,我想这样看 5555555555,因此当用户点击电话号码时,它应该调用该特定号码。

这是我的代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
if indexPath.row == 2 {

print("its working...")

guard let phoneNumber = self.place.phoneNumber,
phoneNumber.count > 0,

let url = URL(string: "tel:\(phoneNumber)")

else { return }

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
} else { return }
}

最佳答案

您的目标是创建一个有效的 tel: URL。您不需要删除电话号码的格式。您只需要正确转义特殊字符即可。

替换:

let url = URL(string: "tel:\(phoneNumber)")

与:

let url = URL(string: "tel:\(phoneNumber.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!)")

关于ios - 如何在没有 ( ) 或 - swift 3 的情况下删除电话号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005717/

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