这是我用来打电话的代码。但它因无效号码而崩溃。 11位数字以6次崩溃开头 但是以 0 开头的 11 位数字工作正常 通常用 10 位数字工作正常。 谁能帮忙?
let myurl=URL(string: "tel://\(selectedEmployeeContact)")
let isInstalled=UIApplication.shared.canOpenURL(myurl!)
if(isInstalled)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(myurl!)
} else {
UIApplication.shared.openURL(myurl!)
}
}
最佳答案
修改您的代码以防止崩溃:-
guard let myurl=URL(string: "tel://\(selectedEmployeeContact)") else {return}
let isInstalled=UIApplication.shared.canOpenURL(myurl)
If your myurl is nil then it will crash because it will force unwrapped the Value.
关于由于手机号码无效,iOS Swift 调用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45358406/