Home
/
Chat
/
iOS

Application

Before you start building your chat, it is important to understand that your Sendbird application has core functionalities to maintain chat service stability and basic features for application management. This page presents how you can use a Sendbird application in your app to ensure optimal performance.


Default settings

To prevent abnormal user activity, a Sendbird application has the following limits on the number of messages per second which a user can send and an open channel can display.

Limits on number of messages per second

Imposed onLimitIf exceeded

User

5 messages per second

Excess messages are neither sent to the channel nor saved in the database but are displayed in the user's channel view.

Open channel

5 messages per second

Excess messages are not displayed, but saved in the database.

* This setting is not effective in a group channel.

The limits are the default settings of our premium features, spam flood protection and smart throttling, which can only be adjusted by Sendbird. Contact our sales team if you require assistance.


Manage connections with Sendbird server

For a seamless chat experience, our Chat SDK manages connections to Sendbird server at an application-wide level. The following table shows how connections between a client app's SBDMain instance and our server are managed. This is according to the states of iOS devices where your native app is working on.

Connections for different app states

App stateConnectionSDK behavior when going to another state

Foreground

Connected continuously

Disconnects the current user from Sendbird server when going to the background.

* Tries to restore the connection and keeps the current user connected to Sendbird server when the connection is lost due to unexpected network issues in the foreground. In this case, restoration attempts and results can be checked in the connection delegate if registered.

Background

Disconnected

Tries to reconnect and establishes the current user's new connection with Sendbird server when going to the foreground.

One user ID can make connections to up to 30 devices or browsers simultaneously. All connections from one user ID are counted and reflected in your application’s concurrent connections. Since they are used to calculate your service billing, caution is advised.


Retrieve a list of users

By creating a SBDApplicationUserListQuery instance and using it, you can retrieve a list of all or certain users in your Sendbird application. The loadNextPageWithCompletionHandler: method returns a list of SBDUser objects which contain information on users within the application.

Objective-C
Swift
Light Color Skin
Copy
// Retrieving all users.
SBDApplicationUserListQuery *listQuery = [SBDMain createApplicationUserListQuery];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // A list of users is successfully retrieved.
    // Through the "users" parameter of the callback method,
    // you can access the data of each user from the result list that Sendbird server has passed to the callback method.
    ...
}];
Light Color Skin
Copy
// Retrieving all users.
let listQuery = SBDMain.createApplicationUserListQuery()

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // A list of users is successfully retrieved.
    // Through the "users" parameter of the callback method,
    // you can access the data of each user from the result list that Sendbird server has passed to the callback method.
    ...
})

With the several different types of filters the SBDApplicationUserListQuery instance provides, you can retrieve a list of specific users that match the set values in the filters. Currently the SBDApplicationUserListQuery instance supports the following three filters:

List of filters

NameFilters...

UserIdsFilter

Users who are using the specified user IDs. Specifying the UserIdsFilter option enables this filter.

MetaDataKeyFilter

Users with metadata containing an item with the specified key and values. Specifying the setMetaDataFilterWithKey:values: option enables this filter.

MetaDataValuesFilter

Users with metadata containing an item with the specified key and values. Specifying the setMetaDataFilterWithKey:values: option enables this filter.

Note: We recommend you set the maximum number of user IDs to 250 in the userIdsFilter. If exceeded, your query may receive an HTTP 414 error indicating that the submitted request data is longer than Sendbird server is willing to interpret.

Objective-C
Swift
Light Color Skin
Copy
// Retrieving certain users using the UserID filter.
SBDApplicationUserListQuery *listQuery = [SBDMain createApplicationUserListQuery];
[listQuery setUserIdsFilter:@["Harry", "Jay", "Jin"]];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
}];

// Retrieving certain users using the MetaDataKey filter.
SBDApplicationUserListQuery *listQuery = [SBDMain createApplicationUserListQuery];
[listQuery setMetaDataFilterWithKey:@"hobby" values:@["movie", "book", "exercise"]];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
}];
Light Color Skin
Copy
// Retrieving certain users using the UserID filter.
let listQuery = SBDMain.createApplicationUserListQuery()
listQuery?.userIdsFilter = ["Harry", "Jay", "Jin"]

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
})

// Retrieving certain users using the MetaDataKey filter.
let listQuery = SBDMain.createApplicationUserListQuery()
listQuery?.metaDataFilterWithKey = ["hobby", ["movie", "book", "exercise"]]

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
})

Block and unblock other users

A user can register other users within an application as friends, start an instant 1-to-1 group chat with a friend, and invite friends to existing group channels. On the other hand, a user can block specific users to stop receiving further messages from them in 1-to-1 group channels and notifications of their messages in 1-to-N group channels. You can choose whether or not users can view which users they have blocked in the channel UI.

A Sendbird application provides two blocking options: including or excluding blocked users when sending invitations and turning on/off push notifications from blocked users. The previous block modes are now deprecated and only supported for customers who have been using them from before.

  • Including or excluding blocked users when sending invitations: determines whether or not to automatically filter out blocked users when a user invites a group of users to a new group channel. The value of this option can be adjusted only from our side before integrating your Sendbird application to an app. If you want to change the value, contact our sales team for further assistance. (Default: including)
  • Turning on/off push notifications from blocked users: determines whether or not to send push notifications to a user for the messages that blocked users sent in a specific 1-to-N group channel where they are members together. The value of this option can be set individually by channel. If you want to use this option, contact our sales team for further assistance. (Default: off)

1-to-1 group channel

Channel listPush notificationsMessages

A user's channel list will not be updated and rearranged from the blocked user's messages.

A user will not be notified that the blocked user sent a message.

New messages sent from the blocked user will not be delivered to the channel, but are saved in the database and displayed in the blocked user's channel view. The blocked user is not aware of their blocked status. A user can only see the messages that the blocked user has sent before being blocked.

* If the blocked user is unblocked, a user can see all the messages except those that were sent during the blocking period.

1-to-N group channel (group chat)

Channel listPush notificationsMessages

For a blocked user's message, a user's channel list will be updated and rearranged.

A user will be notified of messages from blocked users if push notifications from blocked users is turned on. Otherwise, they will not be notified.

All the messages from blocked users are delivered to the channel. You can choose whether a user can view which users they have blocked in the UI of the channel.

You can allow a user to block and unblock other users by implementing the following code to your client app.

Objective-C
Swift
Light Color Skin
Copy
// Blocking a user.
[SBDMain blockUser:USER completionHandler:^(SBDUser * _Nullable blockedUser, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // The blocked user can be retrieved through the "blockedUser" parameter of the callback method.
    ...
}];

// Unblocking a user.
[SBDMain unblockUser:USER completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // The user is successfully unblocked.
    ...
}];
Light Color Skin
Copy
// Blocking a user.
SBDMain.blockUser(USER, completionHandler: { (blockedUser, error) in
    guard error == nil else {
        // Handle error.
    }

    // The blocked user can be retrieved through the "blockedUser" parameter of the callback method.
    ...
})

// Unblocking a user.
SBDMain.unblockUser(USER, completionHandler: { (error) in
    guard error == nil else {
        // Handle error.
    }

    // The user is successfully unblocked.
    ...
})

Note: You can use the blockUserId:completionHandler: and unblockUserId:completionHandler: methods, instead of the blockUser:completionHandler: and unblockUser:completionHandler:, as they have the same functionalities.


Retrieve a list of blocked users

Using the SBDBlockedUserListQuery's loadNextPageWithCompletionHandler: method, you can retrieve a list of all or certain users who are blocked by a specific user in your Sendbird application. The method returns a list of SBDUser objects which contain information on blocked users.

Objective-C
Swift
Light Color Skin
Copy
// Retrieving all blocked users.
SBDBlockedUserListQuery *listQuery = [SBDMain createBlockedUserListQuery];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // A list of blocked users is successfully retrieved.
    // Through the "users" parameter of the callback method,
    // you can access the data of each blocked user from the result list that Sendbird server has passed to the callback method.
    ...
}];
Light Color Skin
Copy
// Retrieving all blocked users.
let listQuery = SBDMain.createBlockedUserListQuery()

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // A list of blocked users is successfully retrieved.
    // Through the "users" parameter of the callback method,
    // you can access the data of each blocked user from the result list that Sendbird server has passed to the callback method.
    ...
})

With the BlockedUserListQuery's UserID filter, you can retrieve a list of the blocked users that match the user IDs in the filter.

Objective-C
Swift
Light Color Skin
Copy
// Retrieving certain blocked users using the UserID filter.
SBDBlockedUserListQuery *listQuery = [SBDMain createBlockedUserListQuery];
[listQuery setUserIdsFilter:@["John", "Daniel", "Jeff"]];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
}]
Light Color Skin
Copy
// Retrieving certain blocked users using the UserID filter.
let listQuery = SBDMain.createBlockedUserListQuery()
listQuery?.userIdsFilter = ["John", "Daniel", "Jeff"]

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    ...
})

Check if a user is online

You can check if a certain user is currently connected to Sendbird server.

Objective-C
Swift
Light Color Skin
Copy
SBDApplicationUserListQuery *listQuery = [SBDMain createApplicationUserListQuery];
[listQuery setUserIdsFilter:@["Jeff"]];

[listQuery loadNextPageWithCompletionHandler:^(NSArray * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {
        // Handle error.
    }

    // users[0] = 'Jeff'
    if (users[0].connectionStatus == SBDUserConnectionStatusOnline) {
        // 'Jeff' is currently online.
        // SBDUserConnectionStatus consists of SBDUserConnectionStatusOnline, SBDUserConnectionStatusOffline, and SBDUserConnectionStatusNonAvailable.
        ...
    }
}];
Light Color Skin
Copy
let listQuery = SBDMain.createApplicationUserListQuery()
listQuery?.userIdsFilter = ["Jeff"]

listQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {
        // Handle error.
    }

    // users[0] = 'Jeff'
    if users?[0].connectionStatus == SBDUserConnectionStatus.online {
        // 'Jeff' is currently online.
        // SBDUserConnectionStatus consists of online, offline, and nonAvailable.
        ...
    }
})