Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sunilkumarr opened this issue Aug 11, 2023 · 1 comment

Comments

@Sunilkumarr
Copy link

Sunilkumarr commented Aug 11, 2023

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?

@Sunilkumarr Sunilkumarr changed the title In iOS Side dock icons Like and Add to watch later are not working in webview iOS 16.6 In iOS Sidedock icons Like and Add to watch later are not working in webview iOS 16.6 Aug 11, 2023
@bdougherty
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants