iOS
Application

Application

Before you start building your own chat, you should understand that your SendBird application has some restrictions on its abilities to maintain the stability of chat service and also gives you ways to work with the application users. With the following information, you can integrate the SendBird application to your app for us to work better together.


Default settings

To prevent a user's abnormal activities, 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.

Imposed onLimitIf exceeded

User

5 messages per second

Excess messages from a user are not sent to a channel, and not saved in the database. But in the user's channel view, the messages are displayed.

Open channel

5 messages per second

Excess messages in an open channel are not displayed, but saved in the database. (This setting is not effective in a group channel.)

The limits above are basic numbers of our premium features, the spam flood protection and smart throttling, which can be adjusted only from our side. If you want assistance on the settings, contact our engineering team.


Manage connections with SendBird server

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

App stateConnectionSDK behavior when going to another state

Foreground

Keep connected

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, the attempts of restoration process and result 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 up to 30 devices or browsers simultaneously. All connections from one user ID are counted and reflected in the CCU (concurrently connected users) which is our service's billing standard, so be careful to use it.


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 *applicationUserListQuery = [SBDMain createApplicationUserListQuery];
[applicationUserListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
// Retrieving all users
let applicationUserListQuery = SBDMain.createApplicationUserListQuery()
applicationUserListQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {   // Error.
        return
    }
})

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

  • UserID filter: filtering users by specifying a list of user IDs.
  • MetaDataKey filter: filtering users by specifying a metadata key and a list of its values (metadata values).

Note: We recommend you set the maximum number of the user IDs to 250 in the UserID filter. 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 *applicationUserListQueryByIds = [SBDMain createApplicationUserListQuery];
[applicationUserListQueryByIds setUserIdsFilter:@["Harry", "Jay", "Jin"]];
[applicationUserListQueryByIds loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];

// Retrieving certain users using the MetaDataKey filter
SBDApplicationUserListQuery *applicationUserListQueryByMetaData = [SBDMain createApplicationUserListQuery];
[applicationUserListQueryByMetaData setMetaDataFilterWithKey:@"hobby" values:@["movie", "book", "exercise"]];
[applicationUserListQueryByMetaData loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];
Light Color Skin
Copy
// Retrieving certain users using the UserID filter
let applicationUserListQueryByIds = SBDMain.createApplicationUserListQuery()
applicationUserListQueryByIds?.userIdsFilter = ["Harry", "Jay", "Jin"]
applicationUserListQueryByIds?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {       // Error.
        return
    }
})

// Retrieving certain users using the MetaDataKey filter
let applicationUserListQueryByMetaData = SBDMain.createApplicationUserListQuery()
applicationUserListQueryByMetaData?.metaDataFilterWithKey = ["hobby", ["movie", "book", "exercise"]]
applicationUserListQueryByMetaData?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {       // Error.
        return
    }
})

Block and unblock other users

A user can block other users to stop receiving any further messages from them in 1-on-1 group channels, and not to be notified of their new messages in 1-on-N group channels. You can choose whether or not a user can view which users they have blocked in the UI of the channel.

A SendBird application provides two blocking options: including or excluding blocked users in 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 it from before.

  • Including or excluding blocked users in invitations: determines for a user whether or not to automatically filter out already blocked users when inviting a group of users to a new group channel. The value of this option can be manually adjusted only from our side before integrating your SendBird application to an app. If you want to change the value, contact our engineering team for further assistance. (Default: including)
  • Turning on/off push notifications from blocked users: determines for a user whether or not to receive push notifications for the messages from already blocked users within a specific 1-on-N group channel where they are members of together. The value of this option can be set individually by channel. If you want to use this option, contact our engineering team for further assistance. (Default: off)
1-on-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 and displayed to 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 previously before blocking.
(If the blocked user is unblocked, a user can see all the messages except those that were sent during the blocking period.)

1-on-N group channel (group chat)
Channel listPush notificationsMessages

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

If the push notifications from blocked users is turned on, messages sent from blocked users will be notified to a user. Otherwise, they will not be notified.

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

You can make users block and unblock other user 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) { // Error.
        return;
    }
}];

// Ublocking a user
[SBDMain unblockUser:USER completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
// Blocking a user
SBDMain.blockUser(USER) { (user, error) in
    guard error == nil else {   // Error.
        return
    }
}

// Unblocking a user
SBDMain.unblockUser(USER) { (error) in
    guard error == nil else {   // Error.
        return
    }
}

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


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 *blockedUserListQuery = [SBDMain createBlockedUserListQuery];
[blockedUserListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
// Retrieving all blocked users
let blockedUserListQuery = SBDMain.createBlockedUserListQuery()
blockedUserListQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {   // Error.
        return
    }
})

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 *blockedUserListQuery = [SBDMain createBlockedUserListQuery];
[blockedUserListQuery setUserIdsFilter:@["John", "Daniel", "Jeff"]];
[blockedUserListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];
Light Color Skin
Copy
// Retrieving certain blocked users using the UserID filter
let blockedUserListQuery = SBDMain.createBlockedUserListQuery()
blockedUserListQuery?.userIdsFilter = ["John", "Daniel", "Jeff"]
blockedUserListQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {       // Error.
        return
    }
})

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 *applicationUserListQuery = [SBDMain createApplicationUserListQuery];
[applicationUserListQuery setUserIdsFilter:@["Jeff"]];
[applicationUserListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }

    if (users[0].connectionStatus == SBDUserConnectionStatusOnline) {
        // SBDUserConnectionStatus consists of SBDUserConnectionStatusOnline, SBDUserConnectionStatusOffline, and SBDUserConnectionStatusNonAvailable.
    }
}];
Light Color Skin
Copy
let applicationUserListQuery = SBDMain.createApplicationUserListQuery()
applicationUserListQuery?.userIdsFilter = ["Jeff"]
applicationUserListQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {   // Error.
        return
    }

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