iOS: Integrating Live Chat as an Embedded View
Updated
The Live Chat SDK provides flexibility to integrate Messenger directly into your app’s UI. Instead of launching Messenger as a standalone activity, you can embed it as a fragment within your host application. This approach allows the chat experience to coexist seamlessly with your app’s navigation, layouts, and lifecycle management.
1. Add Messenger view controller in your app layout
Add SPRMessengerViewController as a child and pin it using your custom layout constraints.
2. Handle close in parent app
Set a close handler and restore parent app UI when Messenger is closed.
Clear handler when needed:
3. Notify layout changes
If parent app layout changes Messenger container size without recreating the view controller, call the updateMessengerWindowLayout method.
Example scenario: Suppose your app supports device rotation or split-screen multitasking, and the size of the container view holding the Messenger changes. In such cases, after updating your layout constraints, call the Messenger’s layout update method to ensure the chat UI resizes correctly.
4. Handle open-from-notification in embedded flow
This section explains how to manage the flow when Live Chat is opened from a notification in an embedded setup.
Components and Methods:
setOpenEmbeddedSPRMessengerHandler: A callback that must be registered in your app. It is triggered when Live Chat is opened from notifications, and the SDK needs your app to show the embedded Live Chat UI first.
LiveChatViewController: Your app’s custom view controller responsible for displaying the embedded Live Chat UI. It manages all chat-related interactions and should be reused if already present in the navigation stack, or created when needed.
handleNotificationIfNeeded: A method on LiveChatViewController that processes any pending notification data. When a notification (such as an in‑app or push notification) is clicked, it opens the Live Chat view inside LiveChatViewController.
If LiveChatViewController manages multiple child view controllers, this method ensures the correct chat screen or context (such as a specific thread or message) is displayed. Always call this method after the Live Chat UI is visible, so the notification’s context is handled appropriately.
Note: Call onComplete only after the Live Chat controller is visible to the user.