I am trying to place a phone call with this code...
let phone = detail.value(forKey: "Phone") as? String
guard let number = URL(string: "telprompt://" (phone)) else { return }
UIApplication.shared.open(number, options: [:], completionHandler: nil)
I attempted to vary my code basically off this answer swift how to make phone call iOS 10?, but I am having difficulty creating a working/error-free function.
Originally my code went like
guard let number = URL(string: "telprompt://"\(phone))...
however, Xcode directed a space between the end quote and open paranthensis for the phone variable while simultaneously deleting "\". Unfortunately, now I am left with the error in the title. A tweak in my code would be appreciated :D
Update 1: I have updated my code to
@IBAction func call(_ sender: Any)
{
let phone = detail.value(forKey: "Phone") as? NSURL
func makeCallToNumber(number: String){
if let url = URL(string: "TEL://\(phone)"){
UIApplication.shared.open(url , options: [:], completionHandler: nil)
}
else{
print("Error")
}
}
}
yet the code is still not bringing up the dialer.
update 2:
I have switched my code to
let phone = detail.value(forKey: "Phone") as? String
if let url = URL(string: "telprompt:\(String(describing: phone))") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
and while I have no errors, no call is being made and this appears in my console. . Unsure what it means.