Integrating UIKit into an Existing App
This tutorial walks you through the process of integrating UIKit into your existing application.
Prerequisites
- Sendbird UIKit library. If you don't have it yet, follow the steps in Send your first message to install the library.
- Sendbird account and Sendbird application to use the UIKit library. If you don't have an account, you can create one here.
- At least two users should be created in the Sendbird dashboard to test the chat functionality. You can create users on Sendbird Dashboard.
How to customize
Step 1 Clone the starter code
In most cases, you will already have an existing application that you want to add chat functionality to. In this tutorial, we will build a simple delivery app first to demonstrate how to integrate UIKit into an existing app. This app requires a chat feature so that users can communicate with their delivery person.
To get started, clone the starter code from the GitHub repository.
You can find the code in the integrate-with-existing-app/before
folder.
The app basically has two screens as follows:
- Login Screen: A simple form to enter the user ID.
- Order Status Screen: A screen to show the order details and the status.
Step 2 Integrate SendbirdUIKit
Now we will integrate the UIKit library to create a channel and open the chat screen when the chat button is tapped. Follow the three steps below to integrate the UIKit library.
- Initialize SendbirdUIKit
- Save the
userId
in the Login screen - When the chat button is clicked, create a channel and open the chat screen.
Step 2-1 Initialize SendbirdUIKit
First, initialize SendbirdUIKit in the AppDelegate class.
- Replace
YOUR_APP_ID
with your Sendbird application ID.
Step 2-2 Save the userId
in the Login screen
Let's change the loginButtonTapped function in LoginViewController.swift
to set the current user and navigate to the order status screen.
By using the SBUGlobals.currentUser
, you can set the current user.
Step 2-3 Open a chat screen
Let's change the chatButtonTapped
function in OrderStatusViewController.swift
to create a channel and open the chat screen.
- By using the SendbirdUI.connect, you can connect to the Sendbird server.
- By using the GroupChannel.createChannel, you can create a channel.
- By using the SBUGroupChannelViewController, you can open the chat screen.
- Be sure to replace
self.orderDetails.deliveryPersonId
with the actual delivery person's user ID.
Step 3 Run the app
Now, you can run the app and test the chat functionality.
Full code
You can refer the full code from the GitHub repository.
Other samples
We have more samples available in our GitHub repository.