admin管理员组文章数量:1391977
On iOS, I can set allowsPictureInPictureMediaPlayback
of a WKWebViewConfiguration
to true
to enable Picture-in-Picture. According to the documentation, this property isn't available on macOS.
Is there any way to enable Picture-in-Picture with a WKWebView
on macOS?
On iOS, I can set allowsPictureInPictureMediaPlayback
of a WKWebViewConfiguration
to true
to enable Picture-in-Picture. According to the documentation, this property isn't available on macOS.
Is there any way to enable Picture-in-Picture with a WKWebView
on macOS?
1 Answer
Reset to default 0I ran into this same issue a while back, and yeah, it’s a bit of a pain that macOS doesn’t have the allowsPictureInPictureMediaPlayback
property like iOS does for WKWebView
. The Apple docs make it pretty clear it’s iOS-only, so we’ve got to get creative.
From what I’ve dug up, there’s no direct built-in way to enable Picture-in-Picture (PiP) in WKWebView
on macOS, but you can lean on the HTML5 Picture-in-Picture API. If your web content supports it (think videoElement.requestPictureInPicture()
in JavaScript), it should work in WKWebView
—kinda like how it does in Safari. I’ve tested this with some basic video pages, and it’s solid when the stars align. Check out MDN’s docs for the nitty-gritty on that.
Now, here’s the catch: if you’re building for the Mac App Store, sandboxing can throw a wrench in things. Some folks have tried using the com.apple.PIPAgent
entitlement to force PiP—there’s chatter about it on Apple’s forums—but Apple’s rejected apps for it unless it’s super justified. So, if you’re not going App Store, you might experiment with that, but it’s dicey.
Another workaround I’ve seen is pulling the video URL out of the WKWebView
and playing it with AVPlayer
, which does support PiP on macOS. It’s a hassle, though, and not always practical if the video’s buried in tricky web code. Kodeco’s got a guide that touches on this if you’re curious.
Honestly, macOS just doesn’t seem as PiP-friendly for web stuff as iOS. If you control the webpage, the HTML5 API is your best shot. Otherwise, you might be stuck tweaking things case-by-case or waiting for Apple to throw us a bone in a future update. Anyone else found a slicker way around this?
Key Citations
Apple WKWebViewConfiguration Docs
MDN Picture-in-Picture API
Apple Developer Forums
Kodeco PiP Guide
本文标签: swiftEnable PictureinPicture for WKWebView on macOSStack Overflow
版权声明:本文标题:swift - Enable Picture-in-Picture for WKWebView on macOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744743444a2622746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论