I don't know what is hapenning but call dialog is not showing and i am getting 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
for you code just change
URL(string: "tel://\(0518858888)")
will work
尝试下面的代码。
UIApplication.shared.open(NSURL(string: "tel://\(9999999999)") as URL)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.