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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -