3

I want to set alert like Safari, when user click on a video url then it will ask for to play or cancel.

currently when I click on video url(a url inside of a loaded page) it directly play the video in AVPlayer.

enter image description here

How do I implement it without auto-start?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shivam Parmar
  • 1,520
  • 11
  • 27

1 Answers1

1

This answer works in my case.

on click of downloadable link where videos will play I use below delegate of wkwebview:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    if navigationAction.navigationType == WKNavigationType.linkActivated {
        print("downloadable link")

        // add alert here

        decisionHandler(WKNavigationActionPolicy.cancel)
    }else{
        decisionHandler(WKNavigationActionPolicy.allow)
}

here(on place of add alert here) you can add the alert same like Safari and use as per your requirement.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shivam Parmar
  • 1,520
  • 11
  • 27