Swift WebKit Picture in Picture

1.8k Views Asked by At

How can you enable Picture-in-Picture on a Swift WebView from WebKit?

At the moment, when you watch a video in a webView and switch to the home screen, you briefly see the picture-in-picture view in the top right on the home screen, but it disappears after a second.

How can you retain it so it doesn't disappear?

Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

Make sure you enabled Picture in Picture under BackgroundModes in Xcode.

TARGETS -> Signing & Capabilities -> Background Mode

enter image description here

If you are trying to embed a youtube video in your webView, PiP won't work. Youtube blocking PiP in iOS webView and Safari.

For youtube videos embedding is better to use the youtube-ios-player-helper framework.