SwiftDeveloper SwiftDeveloper - 1 year ago 118
iOS Question

Call phone action don't work

Hello I've button action for call number , but when I used it don't call and nothing shows.

My codes under below.

@IBAction func callPhone(sender: AnyObject) {
UIApplication.shared().canOpenURL((NSURL(string: "tel://1234567890")! as URL))

Thank You !

Answer Source

Proper Swift 3.0 Code

if let url = URL(string: "tel://\(phoneNumber)") {
            UIApplication.shared().open(url, options: [:], completionHandler: nil)

In Swift 3.0 NSURL have changed to URL. And sharedApplciation changed to shared. Also OpenURL changed to open, they have added a bunch other parameters to the openmethod, you can pass empty dictionary in options and nil in the completionHandler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download