我试图将电话号码格式化为" 01-800-234-0445"用于调用屏幕。在尝试执行呼叫之前,我可以将其格式化为正确的格式,但是当呼叫在" 018002340445"格式。我认为这与编码有关,这是我到目前为止所做的:
phone =" 01-800-234-0445" (用于executeCall手机参数)
private func executeCall(phone:String){
let formattedPhone = phone.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)!//this formatting doesn't appear to be doing anything
if let url = URL(string: "tel://" + formattedPhone), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
}