2

我想要做的是,当有人通过下面的 UIAlertAction 序列按下“呼叫位置”按钮时,我希望它加载电话并拨打我之前在代码中估算的电话号码(在 ViewDidLoad 中)。这是我的 annotationView - calloutAccessory 代码,我必须这样做:

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
    let stores = view.annotation as! Stores
    let placeHours = stores.seasonhours
    let placeHours1 = stores.offseasonhours
    let phoneInfo = stores.phone

    let ac = UIAlertController(title: placeHours, message: placeHours1, preferredStyle: .alert)
    ac.addAction(UIAlertAction(title: "Call Location", style: .default))
    ac.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
    present(ac, animated: true)


}

我将如何编码?

注意:我是编码新手,因此不胜感激。

更新:我自己想通了。在第一行 ac.addAction 中,我将其更改为:

ac.addAction(UIAlertAction(title: "Call Location", style: .default, handler:    {action in
if let url = URL(string: "tel://\(phoneInfo)") {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
})) 
4

0 回答 0