Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if valid url WebView Swift

Tags:

ios

swift

I want to check if the video url works before embedding it into my webView. Because if the user enters a url that doesn't resolve or contain video then the webView will display a whitebox

  // (if MyVariables.link is valid)
  {....
  let Code:NSString = "<iframe width=\(width) height=\(height) src=\(MyVariables.link)  frameborder=\(frame)></iframe>";
  self.wView.loadHTMLString(Code as String, baseURL: nil)
  }
like image 248
SlopTonio Avatar asked Mar 15 '23 23:03

SlopTonio


1 Answers

Check the url by using canOpenURL from UIApplication

 if let url = NSURL(string: yourUrlString) {
    var canOpen = UIApplication.sharedApplication().canOpenURL(url)
 }
like image 114
Christian Avatar answered Mar 28 '23 04:03

Christian