Notifications Guide v1
Notifications
Version 1

Render a notification channel

Copy link

There are two different views when rendering notification channels: Feed and Chat. Feed view shows all notifications in a list form while Chat view shows notifications in the form of a user-to-user group channel.

This guide demonstrates how to render a channel by view type for the following platforms:


Feed view

Copy link

The following items are key elements of SBUFeedNotificationChannelViewController that are used to create a Feed view of the notification channel.

Initialize

Copy link

You can start building a new Feed view through the SBUFeedNotificationChannelViewController class by following the code below. Once the view is created, display the channel anywhere you want in your app. The channel URL of the feed notification channel can be found on Sendbird Dashboard under Notifications > Channels.

let feedChannelViewController = SBUViewControllerSet.FeedNotificationChannelViewController.init(
    channelURL: "FEED_NOTIFICATION_CHANNEL_URL"
)

If you already have an existing FeedNotificationChannelViewController, you need to update channel information before displaying the Feed view.

let feedChannelViewController = <YOUR_FEED_CHANNEL_VIEWCONTROLLER>
feedChannelViewController.reloadChannel(
    channelURL: "FEED_NOTIFICATION_CHANNEL_URL"
)

Module components

Copy link

In the SBUFeedNotificationChannelViewController class, SBUFeedNotificationChannelModule and its components are used to display the Feed view. The module is composed of two components: headerComponent and listComponent.

Configure new notification badge

Copy link

A green badge appears above the notification bubble when the current user receives a new notification in the Feed view. This badge is displayed based on the Feed's last read time value at the time of view creation. However, this time value remains the same while the Feed view is in the foreground, which prevents the badge from disappearing even if the user's already seen the notification. If you want to update the last read time value, see the code below. You can also call the updateLastSeenAt(_:) method in SBUFeedNotificationChannelViewModel instead.

// Feed notification channel view controller
feedChannelViewController.updateLastSeenAt()

Refresh notification collections

Copy link

If you've authenticated to the Sendbird server by calling SendbirdUI.authenticateFeed(completionHandler:), there's no WebSocket connection between the UIKit and the Sendbird server. Due to the lack of connection, the UIKit can't receive real-time events to notify the user with updated information about the feed channel.

The UIKit will automatically refresh the notification collections when the client app is brought to foreground or when the device's network connection has changed. In the case that the collection information is received as a push notification from the client app, you can refresh the content of all valid notification collections.

Note: NotificationCollection is valid only if the isLive flag is set to true.

SendbirdChat.refreshNotificationCollections()
// The content of the notification collection has been refreshed.

Chat view

Copy link

The following items are key elements of SBUChatNotificationChannelViewController that are used to create a Chat view of the notification channel.

Initialize

Copy link

Before creating the Chat view, implement the code below if you're already using a channel view in your app with standard modal and navigation. The channel URL of the chat notification channel can be found on Sendbird Dashboard under Notifications > Channels.

SendbirdUI.moveToChannel(
    channelURL: "CHAT_NOTIFICATION_CHANNEL_URL",
    basedOnChannelList: true
)

If you're currently using Chat UIKit for iOS features with a specific root view controller, implement the code below.

SendbirdUI.moveToChannel(
    channelURL: "CHAT_NOTIFICATION_CHANNEL_URL",
    basedOnChannelList: true,
    rootViewController: <YOUR_ROOT_VIEWCONTROLLER>
)

If you're using the channel view differently in your app than the cases mentioned above, then you need to find the existing ChatChannelViewController object and display the view in your app. You need to also update channel information before displaying the Chat view if you already have an existing ChatNotificationChannelViewController,

let chatChannelViewController = <YOUR_CHAT_CHANNEL_VIEWCONTROLLER>
chatChannelViewController.reloadChannel(
    channelURL: "CHAT_NOTIFICATION_CHANNEL_URL"
)

Module components

Copy link

In the SBUChatNotificationChannelViewController class, SBUChatNotificationChannelModule and its components are used to display the Chat view. The module is composed of two components: headerComponent and listComponent.


Android

Copy link

Feed view

Copy link

A Feed view of the notification channel is composed of three components: header, notification list, and notification list status.

Chat UIKit Android for Notifications provides both activity and fragment to create a Feed view. You can choose which one to build your app with and you may solely use activity instead of fragment if you wish to. You can build a Feed view through FeedNotificationChannelActivity, which uses UIKitFragmentFactory to create views. The channel URL of the Feed notification channel can be found on Sendbird Dashboard under Notifications > Channels.

Start an activity

Copy link

You can start an activity by using intent to move from one activity to FeedNotificationChannelActivity as shown below:

JavaKotlin
Intent intent = FeedNotificationChannelActivity.newIntent(context, "FEED_CHANNEL_CHANNEL_URL");
startActivity(intent);

Create a fragment

Copy link

FeedNotificationChannelActivity allows you to create a basic FeedNotificationChannelFragment through UIKitFragmentFactory and FeedNotificationChannelFragment.Builder. UIKitFragmentFactory has a set of methods that build each fragment, whereas the builder class provides APIs to customize the UI of the data and event handlers used in FeedNotificationChannelFragment.

JavaKotlin
FeedNotificationChannelFragment fragment = new FeedNotificationChannelFragment.Builder("FEED_CHANNEL_CHANNEL_URL").build();

Note: To use the UIKit's fragments as a nested fragment, refer to the Android Developer Documentation's Nested Fragments.

Configure new notification badge

Copy link

A green badge appears above the notification bubble when the current user receives a new notification in the Feed view. This badge is displayed based on the feed's last read time value at the time of view creation. However, this time value remains the same while the Feed view is on foreground, which prevents the badge from disappearing even if the user's already seen the notification. If you want to update the last read time value, see the code below.

JavaKotlin
// Retrieve the Feed notification channel fragment.
// This is the fragment that you used to create the Feed view.
NotificationChannelFragment fragment = getNotificationChannelFragment();

// Updates to the last read time value on the channel.
notificationFragment.updateLastReadTimeOnCurrentChannel();

Refresh notification collections

Copy link

If you've authenticated to the Sendbird server by calling SendbirdUIKit.authenticateFeed(), there's no WebSocket connection between the UIKit and the Sendbird server. Due to the lack of connection, the UIKit can't receive real-time events to notify the user with updated information about the feed channel.

The UIKit will automatically refresh the notification collections when the client app is brought to foreground or when the device's network connection has changed. In the case that the collection information is received as a push notification from the client app, you can refresh the content of all valid notification collections.

Note: NotificationCollection is valid only if the isLive flag is set to true.

JavaKotlin
SendbirdChat.refreshNotificationCollections();
// The content of the notification collection has been refreshed.

Chat view

Copy link

A Chat view of the notification channel is composed of three components: header, notification list, and notification list status.

Chat UIKit Android for Notifications provides both activity and fragment to create a Chat view. You can choose which one to build your app with and you may solely use activity instead of fragment if you wish to. You can build a Chat view through ChatNotificationChannelActivity, which uses UIKitFragmentFactory to create views. The channel URL of the Chat notification channel can be found on Sendbird Dashboard under Notifications > Channels.

Start an activity

Copy link

You can start an activity by using intent to move from one activity to ChatNotificationChannelActivity as shown below:

JavaKotlin
Intent intent = ChatNotificationChannelActivity.newIntent(context, "CHAT_NOTIFICATION_CHANNEL_URL");
startActivity(intent);

Create a fragment

Copy link

ChatNotificationChannelActivity allows you to create a basic ChatNotificationChannelFragment through UIKitFragmentFactory and ChatNotificationChannelFragment.Builder. UIKitFragmentFactory has a set of methods that build each fragment, whereas the builder class provides APIs to customize the UI of the data and event handlers used in ChatNotificationChannelFragment.

JavaKotlin
ChatNotificationChannelFragment fragment = new ChatNotificationChannelFragment.Builder(“CHAT_NOTIFICATION_CHANNEL_URL”).build();

Note: To use the UIKit's fragments as a nested fragment, refer to the Android Developer Documentation's Nested Fragments.