Open web url link in browser in Swift
You need to check
like this
if let url = URL(string: urlSting.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
Also try removing and/or adding https://
prefix,
and if does not work then simply do:
if let url = URL(string: urlSting), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
Please try this.
if let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}