ios - SFSafariViewController crash: The specified URL has an unsupported scheme. -
my code:
if let url = nsurl(string: "www.google.com") { let safariviewcontroller = sfsafariviewcontroller(url: url) safariviewcontroller.view.tintcolor = uicolor.wantoprimaryorangecolor() presentviewcontroller(safariviewcontroller, animated: true, completion: nil) }
this crashes on initialization exception:
the specified url has unsupported scheme. http , https urls supported
when use url = nsurl(string: "http://www.google.com")
, fine. loading url's api , hence, can't sure prefixed http(s)://
.
how tackle problem? should check , prefix http://
always, or there's workaround?
you can check availability of http in url
string before creating nsurl
object.
put following code before code , solve problem (you can check https
in same way)
var strurl : string = "www.google.com" if strurl.lowercasestring.hasprefix("http://")==false{ strurl = "http://".stringbyappendingstring(strurl) }
Comments
Post a Comment