[英]Given a phone number, how do I make a phone call in iOS?
我有一個從CloudKit下載的字符串“ 3133133313”中包含的10位電話號碼。
我希望使用該號碼撥打電話。 因此,我有Apple建議的代碼。
let call = detail.value(forKey: "Phone") as? String
let url = URL(string: call!)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
不幸的是,此代碼不起作用。 我在這里想念的可能很明顯。
多虧了Leo Dabus,
我只需要在每個電話號碼中添加“ tel://”方面。 在這個項目中,我決定將此代碼段添加到函數中,而不是CloudKit記錄中。
if let call = detail.value(forKey: "Phone") as? String,
let url = URL(string: "tel://\(call)"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.