Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
User
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Ban and unban a user

Operators of an open or group channel can remove any users that behave inappropriately in the channel using the ban feature. A banned user is immediately kicked out of the channel, but allowed to participate in the channel again after a set period of time has passed. Operators can ban and unban users using the following code.

// Ban a user.
channel.banUser(USER, seconds: SECONDS, description: DESCRIPTION) { (error) in
    guard error == nil else {
        // Handle error.
        return
    }

    // The user is successfully banned from the channel.
    // You can display a message to let the user know they have been banned.
}

// Unban a user.
channel.unbanUser(USER) { (error) in
    guard error == nil else {
        // Handle error.
        return
    }

    // The user is successfully unbanned.
    // You can display a message to let the user know they have been unbanned.
}

Note: Instead of the banUser(_:seconds:description:completionHandler:) and unbanUser(_:completionHandler:) methods, you can use banUser(userId:seconds:description:completionHandler:) and unbanUser(userId:completionHandler:), as they can perform the same action.