Chat UIKit iOS v2
Chat UIKit iOS
Chat UIKit
iOS
Version 2
Sendbird Chat UIKit v2 for iOS is no longer supported as a new version is released. Check out our latest Chat UIKit v3

Send your first message

Copy link

Sendbird UIKit for iOS is a set of prebuilt UI components that allows you to easily craft an in-app chat with all the essential messaging features. Our development kit includes light and dark themes, text fonts, colors and more. You can customize these components to create an interactive messaging interface unique to your brand identity.

Sendbird UIKit supports both open channels and group channels. Follow the guide below to start sending a message from scratch using Objective-C or Swift.

Note: To build an iOS chat app with UIKit, see our iOS UIKit tutorial. To learn how to customize in-app chat on iOS, see this tutorial.


Requirements

Copy link

The minimum requirements for UIKit for iOS are:

  • iOS 11.0 and later
  • Swift 5.0+ / Objective-C
  • Sendbird Chat SDK for iOS 3.1.28 and later
  • Xcode 14.1 and later

Note: Starting on April 25, 2023, you must build and test your app with Xcode 14.1 or later to submit to the App Store. You can use the existing Sendbird SDK versions built with both Xcode 13.x and Xcode 14.1+ but Sendbird is repackaging Chat UIKit for iOS with Xcode 14.1 and minimum iOS version of 11.0 starting on April 25, 2023.


Before you start

Copy link

Before installing Sendbird Chat SDK, you need to create a Sendbird application on the Sendbird Dashboard, which comprises everything required in a chat service including users, messages, and channels. You will need the App ID of your Sendbird application when initializing the Chat SDK.

Note: Each Sendbird application can be integrated with a single client app. Within the same application, users can communicate with each other across all platforms, whether they are on mobile devices or on the web.


Get started

Copy link

You can start building a modern messaging experience in your app by installing Sendbird UIKit. This developer kit is an add-on feature to Sendbird Chat SDK so installing it will also install the core Chat SDK. The minimum requirement of Chat SDK for iOS is 3.1.28 or later.

Step 1 Create a project

Copy link

To get started, open Xcode and create a new project. Sendbird UIKit supports both objective-c and swift.

Step 2 Install UIKit

Copy link

You can install UIKit for iOS through either Swift Packages, CocoaPods, or Carthage.

Swift Packages

Copy link
  1. In Xcode, select File > Add Packages.

  2. Search for SendbirdUIKit spm repository and add it to your Package repository. You can also choose the dependency rule that you want to use in the repository and keep the latest version by selecting the main-v2 branch.

https://github.com/sendbird/sendbird-uikit-ios-spm.git
  1. When finished, Xcode automatically begins resolving and downloading your dependencies to the repository in the background.

Note: A build error may occur whlie using Swift packages with Xcode due to issues with caching. To resolve this error, try resetting the Xcode package caches. Open the File menu, go to Packages, and select Reset Pacakge Caches. This deletes all local package data and redownloads each package from its online source.

CocoaPods

Copy link
  1. Add SendBirdUIKit into your Podfile in Xcode as below:
platform :ios, '11.0'
use_frameworks!

target YOUR_PROJECT_TARGET do
    pod 'SendBirdUIKit', '~> 2.0' # Add this line.
end
  1. Install the SendBirdUIKit framework through CocoaPods.
$ pod install
  1. Update the SendBirdUIKit framework through CocoaPods.
$ pod update

Carthage

Copy link
  1. Add SendBirdUIKit and SendBirdSDK into your Cartfile as below:
github "sendbird/sendbird-uikit-ios" ~> 2.0
github "sendbird/sendbird-ios-framework" ~> 3.0
  1. Install the SendBirdUIKit framework through Carthage.
$ carthage update --use-xcframeworks

Note: Building or creating the SendbirdUIKit framework with Carthage can only be done using the latest Swift. If your Swift is not the most recent version, the framework should be copied into your project manually.

  1. Go to your Xcode project target's General settings tab in the Frameworks and Libraries section. Then drag and drop on the disk of each framework from the <YOUR_XCODE_PROJECT_DIRECTORY>/Carthage/Build folder.

Note: Errors may occur if you're building your project with Xcode 11.3 or earlier versions. To fix these errors, refer to Handle errors caused by unknown attributes.

Step 3 Initialize with APP_ID

Copy link

To integrate and run Sendbird UIKit in your app, you need to initialize it first. Initialize the SendBirdUIKit instance through AppDelegate.

Note: Local caching has now been added so that the client app can locally cache and retrieve channel and message data. The addition of this functionality requires the database to be reset and migrated. As a result of DB migration in the server, the initialization process of the SendBirdUIKit instance is now asynchronous and requires you to receive a callback function before you can move onto the next step. Once the database finishes migrating, completionHandler is called. If the database fails to migrate, the completionHandler block is called with an error. If the database successfully migrates, there is no error and you can proceed to the next step. Refer to the updated code below.

SwiftObjective-C
// AppDelegate.swift

import SendBirdUIKit
...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ...

    let APP_ID = "YOUR_APP_ID"  // Specify your Sendbird application ID.
    SBUMain.initialize(applicationId: APP_ID) {
        // DB migration has started.
    } completionHandler: { error in
        // If DB migration is successful, proceed to the next step.
        // If DB migration fails, an error exists.
    }

    ...

}

Step 4 Set current user

Copy link

User information must be set as CurrentUser in the SBUGlobals prior to launching Sendbird UIKit. This information will be used for various tasks within the kit, and if you don't set CurrentUser in advance, there will be restrictions in your usage. The userID field shown below must be specified. Other fields such as nickname and profileUrl are optional, and if not specified, they'll be filled with default values.

Set CurrentUser for UIKit through the AppDelegate as below:

Note: Even if you don't use AppDelegate, you should still register user information before launching a chat service.

SwiftObjective-C
// AppDelegate.swift

import SendBirdUIKit
...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ...

    // Case 1: USER_ID only
    SBUGlobals.CurrentUser = SBUUser(userId: {USER_ID})

    // Case 2: Specify all fields
    SBUGlobals.CurrentUser = SBUUser(userId: {USER_ID}, nickname:{(opt)NICKNAME} profileUrl:{(opt)PROFILE_URL})
    ...
}

Step 5 Display channel list

Copy link

SBUChannelListViewController is the starting point for launching UIKit in your app. Implement the code below wherever you would like to start UIKit. You can see a complete list of group channels that you're a member of.

SwiftObjective-C
import SendBirdUIKit;
...

let channelListVC = SBUChannelListViewController()
let naviVC = UINavigationController(rootViewController: channelListVC)
self.present(naviVC, animated: true)

...

Note: If you are already using a navigation controller, you can use the pushViewController function.

Step 6 Send your first message

Copy link

You can now run the app on a simulator or a plugged-in device. To send a message, you must first create a group channel by tapping the icon in the top-right corner. Then, you can select users you wish to invite as members to your channel. Once the channel has been created, enter your first message and send.

Note: Sendbird UIKit offers features to attach or save files such as photos, videos, and documents in addition to sending text messages. To learn more about using those features, refer to Get attachment permission in the sample app.

You've successfully sent your first message with Sendbird.

Note: If you wish to distribute your application in the App store and remove unnecessary architectures in the application's build phase, go to Distribution settings in the sample app.


Get attachment permission

Copy link

Sendbird UIKit allows users to attach or save files such as photos, videos, and documents. To use these functionalities, you need to request permission from users using your client apps.

Media attachment permission

Copy link

Client apps must acquire permission from end users to use their photos or save media to their library. Once the permission is granted, users can send image or video messages and download media assets.

...
<key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) would like access to your photo library</string>
<key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your camera</string>
<key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your microphone (for videos)</string>
<key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to save photos to your photo library</string>
...

Document attachment permission (optional)

Copy link

To attach documents from iCloud to file messages, you need to activate the iCloud feature. Once activated, users can send file messages containing documents from iCloud. Go to your Xcode project's Signing & Capabilities, add + Capability, and select iCloud. Check iCloud Documents.


UIKit components

Copy link

UIKit for iOS manages the lifecycle of its ViewController along with various views and data from the Chat SDK for iOS. UIKit components are as follows:


List of components

Copy link
ComponentDescription

SBUChannelListViewController

A ViewController that manages a channel list.

SBUChannelViewController

A ViewController that manages a 1-on-1 chat channel.

SBUChannelSettingViewController

A ViewController that manages the channel settings.

SBUCreateChannelViewController

A ViewController that creates a channel.

SBUInviteUserViewController

A ViewController that invites a user to a channel.

SBUMemberListViewController

A ViewController that shows a list of members in a channel.

SBUTheme

A singleton that manages themes.

SBUColorSet

A singleton that manages color sets.

SBUFontSet

A singleton that manages font sets.

SBUMain

A class that contains static functions required when using Sendbird UIKit.

SBUGlobals

A class that contains static attributes required when using Sendbird UIKit.