iosnsnotificationsfsafariviewcontroller

Detecting and intercepting video playback in SFSafariViewController


I am using SFSafariViewController in my app. When the user plays a video I have to show a pop up asking whether the user wants to download the videos. I have done this with UIWebView and AVPlayerItemBecameCurrentNotification. But this is not working in SFSafariViewController. Can someone give me a solution to this?

Here is the code of adding observer to SFSafariViewController

NotificationCenter.default.addObserver(self.safariViewController!, selector: #selector(self.playerItemBecameCurrent), name: NSNotification.Name(rawValue: "AVPlayerItemBecameCurrentNotification"), object: nil)

Thanks


Solution

  • To be honest, this would not be possible in SFSafariViewController.

    SFSafariViewController isn't open for inspection/interception like UIWebView and WKWebView. Given the control interfaces with the devices KeyChain it makes sense from a security standpoint too.

    You very much can only give it a URL and a set of 2 customisable options.

    Revert to a WKWebView or at worst, UIWebView.

    Appreciate my answer is late, I hope you found it useful