4

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)
  }
SlopTonio
  • 1,105
  • 1
  • 16
  • 39

1 Answers1

7

Check the url by using canOpenURL from UIApplication

 if let url = NSURL(string: yourUrlString) {
    var canOpen = UIApplication.sharedApplication().canOpenURL(url)
 }
Christian
  • 22,585
  • 9
  • 80
  • 106
  • Edited my answer. The return doesn't work if your method doesn't return a bool. So you can save your information in canOpen and check this variable. – Christian Aug 26 '15 at 15:01