SFSafariViewController crash: The specified URL has an unsupported scheme

后端 未结 4 1907
渐次进展
渐次进展 2021-02-07 06:23

My code:

if let url = NSURL(string: \"www.google.com\") {
    let safariViewController = SFSafariViewController(URL: url)
    safariViewController.view.tintColor         


        
4条回答
  •  死守一世寂寞
    2021-02-07 07:26

    You can check for availability of http in your url string before creating NSUrl object.

    Put following code before your code and it will solve your problem (you can check for https also in same way)

    var strUrl : String = "www.google.com"
    if strUrl.lowercaseString.hasPrefix("http://")==false{
         strUrl = "http://".stringByAppendingString(strUrl)
    }
    

提交回复
热议问题