0

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?

1
  • Needs to be success() and failure() you're not actually calling the closures. Commented Jun 12, 2016 at 20:02

1 Answer 1

1

The reason nothing is happening here is that you're not calling the closures. Closures should be called like any other function in swift, like so:

success() failure()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.