我想在将视频网址嵌入到我的webView之前检查视频网址是否有效。因为如果用户输入的网址无法解析或包含视频,则webView将显示白盒
// (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)
}
答案 0 :(得分:6)
使用canOpenURL
UIApplication
检查网址
if let url = NSURL(string: yourUrlString) {
var canOpen = UIApplication.sharedApplication().canOpenURL(url)
}