2017-08-17 27 views

回答

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) 
     } 
    } 
} 
+0

@TaeHunYu添加子視圖如果是這樣,請批准它作爲公認的答案 – EgzonArifi