# Does meeting sdk iOS support Picture-in-picture?

**URL:** <https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877>\
**Category:** iOS\
**Created:** [January 31, 2024, 9:59am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877 "2024-01-31T09:59:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newnapatsorn0048](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/newnapatsorn0048/32/56068_2.png) [@newnapatsorn0048](https://devforum.zoom.us/u/newnapatsorn0048)\
**Post date:** [January 31, 2024, 9:59am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877/1 "2024-01-31T09:59:54Z")

</div>

Hello, I’m new developer and wondering if it’s possible to display video from a meeting sdk in Picture in Picture.

---

<div class="post-metadata">

**Author:** ![richard.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/richard.zoom/32/41061_2.png) [@richard.zoom](https://devforum.zoom.us/u/richard.zoom)\
**Post date:** [February 2, 2024, 1:13am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877/2 "2024-02-02T01:13:29Z")

</div>

Hello,

The MSDK does support picture-in-picture. To do so, you will need to integrate CallKit into your app. The following conditions must be met:

1. A VoIP call in a Default UI meeting is made with CallKit.
2. EnableVideoCallingPictureInPicture under MobileRTCMeetingSettings is set to true.
3. “Audio, Airplay, and Picture in Picture” is enabled in background mode in the project.
4. onCheckIfMeetingVoIPCallRunning delegate method of MeetingServiceDelegate returns true.

For details, please see below:

Adding Picture-in-Picture to Zoom Meeting SDK iOS apps

**Prerequisites**

1. Enable “Audio, Airplay, and Picture in Picture” and “Voice over IP” under Background Modes in the Project’s Signing & Capabilities tab

![](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/0/8/0811eb0e74780ebdd818880ce94c8277460d53c5.png)

1. Picture-in-Picture can only be performed from the Zoom Default UI. The following steps will **not** work with Custom UI.

**Enable Picture-in-Picture for the Meeting SDK**

First, we must call [EnableVideoCallingPictureInPicture](https://marketplacefront.zoom.us/sdk/meeting/ios/interface_mobile_r_t_c_meeting_settings.html#a69541638da9ce70a268f8680968a3691) from the [MobileRTCMeetingSettings](https://marketplacefront.zoom.us/sdk/meeting/ios/interface_mobile_r_t_c_meeting_settings.html) class. We can do so before we join the meeting with the [MobileRTCMeetingService](https://marketplacefront.zoom.us/sdk/meeting/ios/interface_mobile_r_t_c_meeting_service.html) object, to ensure that the setting has been set.

```auto
if let meetingSettings = MobileRTC.shared().getMeetingSettings() {
meetingSettings.enableVideoCallPicture(inPicture: true)
}

meetingService.joinMeeting(with: joinMeetingParameters)

```

To confirm that the setting is enabled, call [videoCallPictureInPictureEnabled](https://marketplacefront.zoom.us/sdk/meeting/ios/interface_mobile_r_t_c_meeting_settings.html#a5aa44ba6afac3895b632ba0dbe7127ef) to receive the corresponding boolean.

Next, we need to implement the [onCheckIfMeetingVoIPCallRunning](https://marketplacefront.zoom.us/sdk/meeting/ios/protocol_mobile_r_t_c_meeting_service_delegate-p.html#afa6c244a565857c2b1921f3ac8abec02) callback function from the [MobileRTCMeetingServiceDelegate](https://marketplacefront.zoom.us/sdk/meeting/ios/protocol_mobile_r_t_c_meeting_service_delegate-p.html) protocol. The purpose of this callback is to confirm to the meeting service that a VoIP meeting is in progress. In our MobileRTCMeetingServiceDelegate, we can implement it like so:

```auto
    func onCheckIfMeetingVoIPCallRunning() -> Bool {
        return providerDelegate.isInCall()
    }

```

We’ll return to the isInCall() function when we get to our custom [CXProvider](https://developer.apple.com/documentation/callkit/cxprovider) delegate class.

**Implementing CallKit**

Picture-in-Picture mode is triggered when a Zoom MSDK app makes a VoIP call. iOS is notified of the call via the CallKit framework. Therefore, CallKit must be implemented.

The official Apple sample app showcasing CallKit can be [found here](https://developer.apple.com/documentation/callkit/making_and_receiving_voip_calls_with_callkit). The accompanying introductory talk, WWDC 2016 session 230, can be [found here](https://wwdctogether.com/wwdc2016/230).

We can invoke CallKit from within the [onMeetingStateChange:](https://marketplacefront.zoom.us/sdk/meeting/ios/protocol_mobile_r_t_c_meeting_service_delegate-p.html#af738d056984dace9cc190879f2c0d8a4) MSDK callback, which is triggered when the [MobileRTCMeetingState](https://marketplacefront.zoom.us/sdk/meeting/ios/_mobile_r_t_c_constants_8h.html#a04b17e9f78d7ddc089b7806c502bee4f) enum changes, such as when a meeting begins connecting, or ends. We should notify iOS via CallKit during the connecting state.

```auto
if state == .connecting {
    let callUUID = UUID()
    let startCallAction = CXStartCallAction(call: callUUID,
                                            handle: CXHandle(type: .generic, value: "test@no.cd"))
    let transaction = CXTransaction(action: startCallAction)
    callController.request(transaction) { error in
        if let error = error {
            print("Error requesting start call transaction:", error.localizedDescription)
            self.providerDelegate.callingUUID = nil
        } else {
            print("Requested start call transaction succeeded")
            self.providerDelegate.callingUUID = callUUID
        }
    }
}

```

The above code creates a [CXStartCallAction](https://developer.apple.com/documentation/callkit/cxstartcallaction) which represents a telephony call has begun- in this case, a VoIP meeting via the Zoom MSDK. We create that action with a UUID (in this case, that we track in the class as a property) and a [CXHandle](https://developer.apple.com/documentation/callkit/cxhandle) that represents the recipient’s “address", that we populate here with dummy data. We create a [CXTransaction](https://developer.apple.com/documentation/callkit/cxtransaction) with the start call action, and an instance of [CXCallController](https://developer.apple.com/documentation/callkit/cxcallcontroller) (also a property) then performs the action via the request function. By doing so, we indicate to CallKit that a meeting has started, meaning we have entered the VoIP process.

The provider delegate is a custom class we create that conforms to the [CXProviderDelegate](https://developer.apple.com/documentation/callkit/cxproviderdelegate) project. The provider delegate acts in response to when an action is performed. In this case, we want to make sure it calls the [fulfill()](https://developer.apple.com/documentation/callkit/cxaction/1648982-fulfill) method whenever an action is successful. In this example, we also have the provider delegate track the calling UUID that is used in the CXHandle. The existence of the UUID is then used in isInCall() to confirm that a meeting is in progress.

We also have to make sure the required delegate callback [providerDidReset](https://developer.apple.com/documentation/callkit/cxproviderdelegate/1771739-providerdidreset) is implemented.

```auto
import CallKit
final class ProviderDelegate: NSObject, CXProviderDelegate {
    
    private let provider: CXProvider
    var callingUUID: UUID?
    
    override init() {
        provider = CXProvider(configuration: type(of: self).providerConfiguration)
        super.init()
        provider.setDelegate(self, queue: nil)
    }
    
    func providerDidReset(_ provider: CXProvider) {
        callingUUID = nil
    }
    
    func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
        action.fulfill()
    }
    
    func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
        action.fulfill()
    }

    func isInCall() -> Bool {
        return callingUUID != nil
    }
    static let providerConfiguration: CXProviderConfiguration = {
        let providerConfiguration = CXProviderConfiguration()
        providerConfiguration.supportedHandleTypes = [.generic]
        
        return providerConfiguration
    }()    
}

```

Finally, we should perform an end action whenever the user ends or leaves a meeting. This would correspond to the MobileRTCMeetingState for an ended meeting.

```auto
    } else if state == .ended {
        let endCallAction = CXEndCallAction(call: providerDelegate.callingUUID ?? UUID())
        let transaction = CXTransaction(action: endCallAction)
        callController.request(transaction) { error in
            if let error = error {
                print("Error requesting end call transaction:", error.localizedDescription)
            } else {
                print("Requested end call transaction succeeded")
                self.providerDelegate.callingUUID = nil
            }
        }
    }
}

```

So as a counterpart to the connecting state, here under connection state ended we create an End Call Action, put it in a transaction object, and have the call controller request it.

With CallKit implemented, picture-in-picture should now work.

Thanks for your patience,  
Richard

---

<div class="post-metadata">

**Author:** ![newnapatsorn0048](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/newnapatsorn0048/32/56068_2.png) [@newnapatsorn0048](https://devforum.zoom.us/u/newnapatsorn0048)\
**Post date:** [February 2, 2024, 5:40am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877/3 "2024-02-02T05:40:12Z")

</div>

Thanks for answering my question. I’m glad the Meeting SDK supports picture-in-picture, but I’m using custom UI. Is there a way to perform picture-in-picture from custom UI?

---

<div class="post-metadata">

**Author:** ![richard.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/richard.zoom/32/41061_2.png) [@richard.zoom](https://devforum.zoom.us/u/richard.zoom)\
**Post date:** [February 5, 2024, 1:21am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877/4 "2024-02-05T01:21:57Z")

</div>

Unfortunately, custom UI does not support picture-in-picture because the user needs to render video when the app is backgrounded, which currently is not supported with custom UI.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [March 6, 2024, 11:22am UTC](https://devforum.zoom.us/t/does-meeting-sdk-ios-support-picture-in-picture/102877/5 "2024-03-06T11:22:24Z")

</div>

Closed on March 6, 2024, 11:22am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
