vimeo / player.js

Interact with and control an embedded Vimeo Player.
https://player.vimeo.com/api/demo
MIT License
1.43k stars 261 forks source link

In iOS Sidedock icons Like and Add to watch later are not working in webview iOS 16.6 #945

Open Sunilkumarr opened 1 year ago

Sunilkumarr commented 1 year ago

Expected Behavior

On clicking on Like or Add to watch it should open in Safari

Actual Behavior

On clicking on the Like icon or Add to Watch later icon in the side dock nothing happens

IMG_2932

Steps to Reproduce

You can use the following ViewController swift class in a sample project and run it on a real device/phone in iOS 16.6.

You will be able to see the issue where clicking on the Like or Add to watch later icon does nothing. It only shows it in the selected mode. The icon button click is not working.

Swift Code Sample

import Foundation
import WebKit

class ViewController: UIViewController {
    private var wkWebView: WKWebView!
    let htmlString = """
             <html>
             <head>
               <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
                <style>
                    body { margin: 0; width:100%%; height:100%%; background-color:#000; }
                    html { width:100%%; height:100%%; background-color:#000; }
                </style>
             </head>
             <body>
                <iframe id="player" src="https://player.vimeo.com/video/852794606?autoplay=1&muted=1" frameborder="0" width="100%" height="100%" allow="autoplay; fullscreen" allowfullscreen></iframe>
                <script src="https://player.vimeo.com/api/player.js"></script>
            <body>
            </body>
            </html>
       """

    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
        setupConstraints()
        wkWebView.loadHTMLString(htmlString, baseURL: URL(string:"https://vimeo.com"))
    }
    func setupView() {
        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.allowsInlineMediaPlayback = true
        wkWebView = WKWebView(frame: .zero, configuration: webConfiguration)
        wkWebView.navigationDelegate = self
        wkWebView.translatesAutoresizingMaskIntoConstraints = false
    }

    func setupConstraints() {
        view.addSubview(wkWebView)
        view.bringSubviewToFront(wkWebView)
        let guide = view.safeAreaLayoutGuide
        wkWebView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        wkWebView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        wkWebView.widthAnchor.constraint(equalTo: guide.widthAnchor).isActive = true
        wkWebView.heightAnchor.constraint(equalTo: wkWebView.widthAnchor, multiplier: 9/16).isActive = true
    }
}

extension ViewController: WKNavigationDelegate {
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        if let url = navigationAction.request.url, navigationAction.navigationType == .linkActivated {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
            decisionHandler(.cancel)
        } else {
            decisionHandler(.allow)
        }
    }
}

Please let me know how to fix that issue?

bdougherty commented 5 months ago

I'm not that familiar with WebView code these days, but I would guess it is the WKNavigationDelegate that is keeping it from working. Do you see that being called when you tap the button? It will be calling window.open() with a login url.