如何添加消息电话呼叫提醒弹出窗口?l

时间:2017-08-17 07:17:03

标签: swift xcode

我想在电话提醒弹出窗口中添加消息。 如何制作?

enter image description here

1 个答案:

答案 0 :(得分:1)

是的,你可以这样做:

func phoneCall(to phoneNumber:String) {

    if let callURL:URL = URL(string: "tel:\(phoneNumber)") {

        let application:UIApplication = UIApplication.shared

        if (application.canOpenURL(callURL)) {
            let alert = UIAlertController(title: "Your Title", message: "Do you want call that number?", preferredStyle: .alert)
            let callAction = UIAlertAction(title: "Call", style: .default, handler: { (action) in
                application.openURL(callURL)
            })
            let noAction = UIAlertAction(title: "No", style: .cancel, handler: { (action) in
                print("Canceled Call")
            })
            alert.addAction(callAction)
            alert.addAction(noAction)
            self.present(alert, animated: true, completion: nil)
        }
    }
}