07-19-2023, 12:19 AM
My code:
if let url = NSURL(string: "www.google.com") {
let safariViewController = SFSafariViewController(URL: url)
safariViewController.view.tintColor = UIColor.primaryOrangeColor()
presentViewController(safariViewController, animated: true, completion: nil)
}
This crashes on initialization only with exception:
> The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported
When I use `url = NSURL(string: "http://www.google.com") `, everything is fine.
I am actually loading URL's from API and hence, I can't be sure that they will be prefixed with `http(s)://`.
How to tackle this problem? Should I check and prefix `http://` always, or there's a workaround?
if let url = NSURL(string: "www.google.com") {
let safariViewController = SFSafariViewController(URL: url)
safariViewController.view.tintColor = UIColor.primaryOrangeColor()
presentViewController(safariViewController, animated: true, completion: nil)
}
This crashes on initialization only with exception:
> The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported
When I use `url = NSURL(string: "http://www.google.com") `, everything is fine.
I am actually loading URL's from API and hence, I can't be sure that they will be prefixed with `http(s)://`.
How to tackle this problem? Should I check and prefix `http://` always, or there's a workaround?