Dùng UIApplication.shared.open(_:options:completionHandler:) với scheme tel://.
- Storyboard: TextField nhập số, Button gọi.
@IBOutlettextField,@IBActionbutton.- Trong action:
@IBAction func callButtonClicked(_ sender: UIButton) {
guard let phone = phoneNumberTextfield.text, !phone.isEmpty,
let url = URL(string: "tel://\(phone)"),
UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Hệ thống hiện confirm "Call / Cancel", người dùng chọn Call thì thực hiện cuộc gọi.