Notifications UIKit v1
Version 1

Install Chat UIKit for Notifications

Copy link

Sendbird Chat UIKit for Notifications is a set of prebuilt UI components that allows you to easily craft an in-app notification channel. Our development kit includes light and dark themes, fonts, colors and more. You can install Chat UIKit for Notifications on the client app to receive notifications sent through the Notifications API or an external platform. Follow the steps below.

Note: Sendbird Notifications uses the existing Chat UIKit for iOS v11.0 and later. To learn more about Sendbird UIKit for Chat, refer to this page.


Copy link

The minimum requirements for Chat UIKit iOS for Notifications are:

  • iOS 11.0 and later
  • Xcode 14.1 and later
  • Swift 5.0+
  • Sendbird Chat SDK for iOS 4.6.0 and later
  • Sendbird Chat UIKit for iOS 3.5.0 and later

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 and notification service including users, notifications, and channels. You will need the Application ID of your Sendbird application when initializing the SDK.

Note: Each Sendbird application can only be integrated with a single client app.

Get started

Copy link

You can start building a notification channel in your app by installing Chat UIKit for Notifications. This developer kit is an add-on feature to Sendbird Chat SDK so installing it will also install the core Chat SDK.

Step 1 Create a project

Copy link

To get started, open Xcode and create a new project. The UIKit supports swift.

Step 2 Install Chat UIKit for Notifications

Copy link

You can install Chat 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 branch.
  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.


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

    pod 'SendBirdUIKit' # Add this line.
  1. Install the SendBirdUIKit framework through CocoaPods.
$ pod install
  1. Update the SendBirdUIKit framework through CocoaPods.
$ pod update


Copy link
  1. Add SendbirdUIKit and SendbirdChatSDK into your Cartfile as below:
github "sendbird/sendbird-uikit-ios"
github "sendbird/sendbird-chat-sdk-ios"
  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 SendbirdUIKit.xcframework and SendbirdChatSDK.xcframework 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 Chat UIKit for Notifications in your app, you need to first initialize the SendbirdUI instance through AppDelegate.

Note: Chat UIKit for Notifications uses local caching so that the client app can locally cache and retrieve channel and message data. The initialization process of the SendbirdUI instance is asynchronous and requires you to receive a callback function before you can move onto the next step. If the database fails to migrate, the completionHandler block is called with an error. If the database successfully migrates, there's no error and you can proceed to the next step. Refer to the updated code below.

Until the initialization of Chat UIKit for Notifications is completed, the progress doesn't advance to the next step. We recommend displaying a loading indicator to show the initialization process so that other succeeding steps should wait. The indicator should be displayed when startHandler is called and hidden when completionHandler is called.

// 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.
    SendbirdUI.initialize(applicationId: APP_ID) { // This is the origin.
        // Initialization of SendbirdUIKit has started.
        // Show a loading indicator.
    } migrationHandler: {
        // DB migration has started.
    } completionHandler: { error in
        // If DB migration is successful, proceed to the next step.
        // If DB migration fails, an error exists.
        // Hide the loading indicator.

Step 4 Set current user

Copy link

User information must be set as currentUser in the SBUGlobals prior to launching Chat UIKit for Notifications. This information will be used for various tasks within the kit, and if you don't set currentUser in advance, there will be restrictions while using the UIKit. 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 the 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.

// AppDelegate.swift

import SendbirdUIKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Initialize with APP_ID on Step 3

    // 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 Set an access token

Copy link

Sendbird server authenticates requests from client apps through two methods: using only user ID or using a user ID and the user's access token.

The user ID authentication method can be useful for applications in development or for existing services where users can log in as guests without additional security. Meanwhile, the access token authentication method generates access tokens for each user through Chat API. Once you request and obtain a token, you need to use that specific access token to authenticate the user.

SBUGlobals.accessToken = {ACCESS_TOKEN}

Step 6 Connect or authenticate to Sendbird server

Copy link

There are two methods to connect to the Sendbird server: SendbirdUI.connect(completionHandler:) and SendbirdUI.authenticateFeed(completionHandler:). If you wish to only implement feed view in your app, it's highly recommended that you authenticate a user to the Sendbird server. If you wish to display chat view or if you're already using Chat SDK and want to additionally implement feed view, then you should connect a user to the Sendbird server.

Connect a user

Copy link

Once the currentUser is set, you can connect the user to the Sendbird server using SendbirdUI.connect(completionHandler:). You need to call this method to connect to the Sendbird server if you wish to only use chat view or use both chat and feed views in your app. The SendbirdUI.connect(completionHandler:) method creates an active WebSocket connection with the server, which allows the Chat SDK to receive real-time events.

If the user ID used during the connection attempt doesn't exist on the Sendbird server, a new user account is created with the specified user ID. The SendbirdUI.connect(completionHandler:) method also automatically updates the user profile on the Sendbird server.

When the view controller is called in UIKit for Notifications, the connection is automatically made with the currentUser which should be already set in the SBUGlobals.

With local caching added to Sendbird Chat SDK, the latest user instance may be returned through the callback even when the user is offline. The local caching functionality stores message and channel data in the local storage and the Sendbird server. As a result, even when a user isn't connected to the server, the user information stored in the local cache is returned through the callback along with an error indicating the offline status.

Refer to the code below to see how to connect a user to the Sendbird server:

SendbirdUI.connect { (user, error) in
    guard let user = user else {
        // The user is offline and you can't access any user information stored in the local cache.
    if let error = error {
        // The user is offline but you can access user information stored in the local cache.
    else {
        // The user is online and connected to the server.

Authenticate a user

Copy link

Once the currentUser is set, you can authenticate the user to the Sendbird server using SendbirdUI.authenticateFeed(completionHandler:). It's highly recommended to use this method to authenticate to the Sendbird server if you're only displaying feed view in the client app.

When keeping your notification channels up to date, you can either create an active WebSocket connection with the server or manually refresh the channel with latest information. In this case where you're displaying a feed view by authenticating a user to the server, you need to refresh notification collections to update your channel. This is because the Chat SDK can't receive real-time events to notify the user with updated information about the feed view when there's no active WebSocket connection with the server.

In order to use the SendbirdUI.authenticateFeed(completionHandler:) method, you must first issue a session token. After authenticating with the session token, you must set a session delegate so that the client app can renew the token upon the user's session expiration. When using SendbirdUI.authenticateFeed(completionHandler:), all session keys are set to expire so it's important that you implement the session handler in order to keep using Sendbird Notifications.

Then, you can call SendbirdUI.authenticateFeed(completionHandler:) to create a new user account or log in with an existing account with the specified user ID and session token. This method authenticates the UIKit and allows it to retrieve feed channels, display notification messages, and more. Refer to the code snippet below.

SendbirdUI.authenticate { user, error in
    // User is authenticated.

Note: If you use the authenticateFeed(completionHandler:) method to connect to the Sendbird server, you can't access group channels or open channels. Error messages, such as User auth session is not allowed to use requested service., will be returned when trying to use Chat SDK's public interfaces.

Step 7 Register push notification credentials

Copy link

In order to receive push notifications, you need to register notification credentials first. Refer to this page on how to upload your push certificate and register a device token.

Step 8 Display notification channel

Copy link

Refer to the codes below to display either Feed view or channel list view where you can see the notifications that were sent to the channel.

Feed view

Copy link

In order to display the Feed view of your notification channel, you need to first find its channel URL on Sendbird Dashboard under Notifications > Channels.

Implement the following code to create a view controller.

let channelVC = SBUViewControllerSet.FeedNotificationChannelViewController.init(
self.navigationController?.pushViewController(channelVC, animated: true)

Channel list view

Copy link

To see the Chat view of your notification channel, you need to first display and call the channel list view in the UIKit. The channel list contains a list of all group channels that the user is a member of along with the notification channel.

Implement the following code to create a view controller.

let channelListVC = SBUViewControllerSet.GroupChannelListViewController.init()
let naviVC = UINavigationController(rootViewController: channelListVC)
viewController?.present(naviVC, animated: true)