Open URL without http or https prefix

This commit is contained in:
Bob Sun 2017-10-10 23:24:44 -07:00
parent 3ca7b71f4a
commit ced3142291

View file

@ -401,7 +401,11 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
} }
func openLink() { func openLink() {
guard let urlString = self.password?.getURLString(), let url = URL(string: urlString) else { var urlString = self.password?.getURLString() ?? ""
if !urlString.lowercased().starts(with: "https://") && !urlString.lowercased().starts(with: "http://") {
urlString = "http://\(urlString)"
}
guard let url = URL(string: urlString) else {
DispatchQueue.main.async { DispatchQueue.main.async {
Utils.alert(title: "Error", message: "Cannot find a valid URL", controller: self, completion: nil) Utils.alert(title: "Error", message: "Cannot find a valid URL", controller: self, completion: nil)
} }