Search code examples
iosipadpicture-in-picture

iPad Picture in Picture Calling restoreUserInterfaceForPictureInPictureStopWithCompletionHandler Randomly


In our application we have a custom player through AVKit that supports picture in picture multitasking on the iPad.

Shortly after the picture in picture is setup, the restoreUserInterfaceForPictureInPictureStopWithCompletionHandler delegate method function is called for seemingly no reason.

In Apple's documentation it says:

This method is called no matter how PiP ends, whether it is because the user ended playback, the user tapped the button to return ongoing video playback to your app, or the video finished playing on its own.

In this case, the user did not end playback, or tap the button to return to the ongoing video in the app, and the video did not finish playing on its own.

What are the other causes for why picture in picture can end randomly?


Solution

  • One case for why this can occur is if you set the AVAudioSession category to ambient, which will tear down the picture in picture controller which therefore calls the restoreUserInterfaceForPictureInPictureStopWithCompletionHandler delegate method. Ensuring this remains at the playback category will ensure the picture in picture controller doesn't get removed.