[英]iOS Tel Phone Call dialog is not showing
I don't know what is hapenning but call dialog is not showing and i am getting canOpenUrl
true 我不知道正在发生什么,但是呼叫对话框未显示,并且我得到
canOpenUrl
true
guard let call = URL(string: "tel://0518858888") else { print("number is invalid") ; return }
UIApplication.shared.open(call, options: [:], completionHandler: nil)
print(UIApplication.shared.canOpenURL(call)) // getting true
guard let callUrl = URL(string: "tel:0518858888"), UIApplication.shared.canOpenURL(callUrl) else {
print("number is invalid")
return
}
UIApplication.shared.open(callUrl, options: [:], completionHandler: nil)
just create a simple function 只需创建一个简单的功能
func makeCall(phoneNumber: String) {
let formattedNumber = phoneNumber.components(separatedBy: NSCharacterSet.decimalDigits.inverted).joined(separator: "")
let phonUrl = "tel://\(formattedNumber)"
let url:NSURL = NSURL(string: phonUrl)!
UIApplication.shared.open(url as URL)
}
call makeCall function from where you want 从所需位置调用makeCall函数
for you code just change 为您的代码只是改变
URL(string: "tel://\(0518858888)")
will work 将工作
尝试下面的代码。
UIApplication.shared.open(NSURL(string: "tel://\(9999999999)") as URL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.