I have a web view inside of my app. I'm currently looking at each request and seeing if they are a youtube video before allowing / canceling the request:
extension WebBrowserViewController: WKNavigationDelegate { func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) { if (urlVideoType(webView.URL!) != VideoUrl.Unknown && urlVideoType(webView.URL!) != VideoUrl.Youtube) { ... } else if urlVideoType(webView.URL!) == VideoUrl.Youtube { // the success and failure part don't work presentYoutubeVideoIfAvailable(webView.URL!, success: decisionHandler(.Cancel), failure: decisionHandler(.Allow)) <------------------- } else { decisionHandler(.Allow) } } } My presentYoutubeVideoIfAvailable method uses this youtube url parser pod: https://github.com/movielala/YoutubeSourceParserKit
However, that makes an async call and I don't know how to make it call the success and failure methods in my method:
func presentYoutubeVideoIfAvailable(url: NSURL, success: (), failure: ()) { Youtube.h264videosWithYoutubeURL(url) { [unowned self] (videoInfo, _) -> Void in switch videoInfo?["url"] as? String { case .Some(let videoUrlString): VideoStore.addVideo(url.absoluteString, title: videoInfo?["title"] as? String ?? "Unknown") success self.presentVideo(NSURL(string: videoUrlString)!) case .None: print("herereee") // gets printed, so I know it's here failure // doesn't do anything. it should be allowing the request but it isn't <----------------------------------- self.showError(.YoutubeParsingFail) } } } I want it so that if the youtube pod returns a url, it should cancel the web view request, and if it fails I want it to continue with the request. How would I do this?
success()andfailure()you're not actually calling the closures.