Above answer is correct but if you want to check you canOpenUrl
or not try like this.
let url = URL(string: "http://www.facebook.com")!
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
//If you want handle the completion block than
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print("Open url : \(success)")
})
}
Note: If you do not want to handle completion you can also write like this.
UIApplication.shared.open(url, options: [:])
No need to write completionHandler
as it contains default value nil
, check apple documentation for more detail.