I’m building an iOS app using Twilio Video 5.10 with Swift. The app supports video calls and works correctly in Picture in Picture (PiP) mode.
However, I’ve noticed an issue:
- When I activate PiP, the local camera feed streams normally to the remote participant.
- If I swipe the PiP window offscreen (hidden at the edge of the display), the remote participant sees my video frozen.
- Audio continues working, but the video stays frozen until I bring the PiP window back onscreen.
Is this expected behavior in iOS PiP with Twilio Video, or is there a workaround to keep the camera feed active while the PiP window is hidden?
I set my CameraSourceOptions enableCameraMultitasking to true
also added com.apple.developer.avfoundation.multitasking-camera-access to my .entitlements
here my CameraManager class:
import TwilioVideo
import AVFoundation
protocol CameraManagerDelegate: AnyObject {
func trackSourceWasInterrupted(track: LocalVideoTrack)
func trackSourceInterruptionEnded(track: LocalVideoTrack)
}
final class CameraManager: NSObject {
weak var delegate: CameraManagerDelegate?
let track: LocalVideoTrack
private let source: CameraSource
var position: AVCaptureDevice.Position {
get { source.device?.position ?? .unspecified }
set {
guard let device = CameraSource.captureDevice(position: newValue) else {
print("No capture device for \(newValue)")
return
}
source.selectCaptureDevice(device) { _, _, error in
if let error { print("Select device error: \(error)") }
}
}
}
deinit { source.stopCapture() }
init?(position: AVCaptureDevice.Position = .front) {
let options = CameraSourceOptions { builder in
builder.enableCameraMultitasking = true
}
guard let source = CameraSource(options: options, delegate: nil) else {
print("Unable to create CameraSource"); return nil
}
guard let track = LocalVideoTrack(source: source, enabled: true, name: "camera") else {
print("Unable to create LocalVideoTrack"); return nil
}
self.source = source
self.track = track
super.init()
self.source.delegate = self
if let device = CameraSource.captureDevice(position: position) {
let config = CameraConfigFactory().makeCameraConfigFactory(captureDevice: device)
source.requestOutputFormat(config.outputFormat)
source.startCapture(device: device, format: config.inputFormat) { _, _, error in
if let error { print("Start capture error: \(error)") }
}
}
}
}
extension CameraManager: CameraSourceDelegate {
func cameraSourceWasInterrupted(source: CameraSource, reason: AVCaptureSession.InterruptionReason) {
print("Camera interruption began: \(reason)")
delegate?.trackSourceWasInterrupted(track: track)
}
func cameraSourceInterruptionEnded(source: CameraSource) {
print("Camera interruption ended")
delegate?.trackSourceInterruptionEnded(track: track)
}
func cameraSourceDidFail(source: CameraSource, error: any Error) {
print("Camera source failed: \(error)")
}
}