The issue is that UIApplication
's canOpenURL()
method simply returns whether a URL can be opened, and does not actually open the URL. Once you've determined whether the URL can be opened (by calling canOpenURL()
, as you have done), you must then call open()
on the shared UIApplication
instance to actually open the URL. This is demonstrated below:
if let url = URL(string: "http://www.apple.com") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
}
open()
also takes an optional completionHandler
argument with a single success
parameter that you can choose to implement to determine if the URL was successfully opened.