UIKit iOS v3
UIKit iOS
UIKit
iOS
Home
/
UIKit
/
iOS
/
Key functions
This is the new Docs for UIKit v3 for iOS. To see the previous Docs, click here.

Configure group channel settings

In UIKit, you can configure channel settings in group channels through the SBUGroupChannelSettingsViewController class. In the group channel settings view, you can change the channel name and cover image, see the member list, and more.

Note: If you set the starting point of your chat service to be the channel list or group channel, you can seamlessly guide your users to the channel settings view.


Initialize

You can start building a group channel settings view through the SBUGroupChannelSettingsViewController class. Use either the init(channelUrl:) or init(channel:) initializer to create the instance and display the view as shown below.

// Case 1: Using channel url.
let channelSettingsVC = SBUGroupChannelSettingsViewController(channelUrl: {CHANNEL_URL})
let navigationController = UINavigationController(rootViewController: channelSettingsVC)
present(navigationController, animated: true)

// Case 2: Using channel object.
let channelSettingsVC = SBUGroupChannelSettingsViewController(channel: {CHANNEL})
let navigationController = UINavigationController(rootViewController: channelSettingsVC)
present(navigationController, animated: true)

Usage

The following items are key elements of SBUGroupChannelSettingsViewController that are used to create a functional group channel settings view.

Module components

In the SBUGroupChannelSettingsViewController class, SBUGroupChannelSettingsModule and its components are used to create and display the group channel settings view. The module is composed of two components: headerComponent and listComponent.

Property nameTypeDefault value

headerComponent

SBUGroupChannelSettingsModule.Header

SBUModuleSet.groupChannelSettingsModule.headerComponent

listComponent

SBUGroupChannelSettingsModule.List

SBUModuleSet.groupChannelSettingsModule.listComponent

Each module component is assigned a value from the SBUModuleSet class and gets added to the view in the setupView() method of the Sendbird UIKit's view life cycle. Then, the configure method of each module component is called to set the property values and display the view.

headerComponent

The headerComponent includes a channel title, a back button that takes the user to the previous view, and an edit button that allows the user to make edits to the channel information. Each property corresponds to the elements in the navigation bar of SBUGroupChannelSettingsViewController.

The following table shows the parameters of the configure method of the headerComponent.

Parameter nameType

delegate

SBUGroupChannelSettingsModuleHeaderDelegate

dataSource

SBUGroupChannelSettingsModuleHeaderDataSource

theme

SBUChannelSettingsTheme

Note: To learn more about the delegate, data source, and the properties of the headerComponent, go to the API reference page.

listComponent

The listComponent shows a settings menu, which includes a toggle button that turns on or off functions such as push notifications, a channel member list, an option to search in channel, and the option to leave the channel. For channel operators, the moderations menu is also available.

The following table shows the parameters of the configure method of the listComponent.

Parameter nameType

delegate

SBUGroupChannelSettingsModuleListDelegate

dataSource

SBUGroupChannelSettingsModuleListDataSource

theme

SBUChannelSettingsTheme

Note: To learn more about the delegate, data source, and the properties of the listComponent, go to the API reference page.

View model

The SBUGroupChannelSettingsViewController class uses a view model that is a type of the SBUGroupChannelSettingsViewModel class. The view model is created in the initializer of the view controller through the createViewModel(channel:channelUrl:) method. When the view model object is created, it retrieves channel information from Chat SDK to the view controller and updates the view through the baseChannelSettingsViewModel(_:didChangeChannel:withContext:) event.

Note: If the value of channel or channelUrl is invalid, the view model cannot retrieve channel information.

The following table shows the parameters of the createViewModel method.

Parameter nameTypeDescription

channel

BaseChannel

Specifies the channel value. (Default: nil)

channelUrl

String

Specifies the URL of the channel. (Default: nil)

Note: To learn more about the methods and the event delegates of the view model, go to this API reference page.

SBUGroupChannelSettingsViewController properties

To learn more about the properties of SBUGroupChannelSettingsViewController, go to the API reference page.


Customization

You can customize the group channel settings view by changing the view controller, module component, and view model that correspond to this key function.

View controller

There are two ways to customize the view controller: change the default view controller value in the global SBUViewControllerSet class or set a single-use custom view controller in the key function.

The custom view controller in the code below is used in the following customization examples.

class CustomViewController: SBUGroupChannelSettingsViewController {
    // Implement custom code here.
}
  1. Change the value of SBUViewControllerSet.GroupChannelSettingsViewController.
SBUViewControllerSet.GroupChannelSettingsViewController = CustomViewController.self

// The view controller will now use `CustomViewController` as the default value.
  1. Use a one-time custom view controller in the group channel settings view.
let channelSettingsVC = CustomViewController(channelUrl: {CHANNEL_URL})
let navigationController = UINavigationController(rootViewController: channelSettingsVC)
present(navigationController, animated: true)

Module component

There are two ways to customize a module component: change the default module component value in the global SBUModuleSet.groupChannelSettingsModule class or set a single-use custom module component in the view controller.

The custom header component in the code below is used in the following customization examples.

class CustomHeader: SBUModuleSet.groupChannelSettingsModule.Header {
    // Implement custom code here.
}
  1. Change the value of SBUModuleSet.groupChannelSettingsModule.headerComponent.
SBUModuleSet.groupChannelSettingsModule.headerComponent = CustomHeader()

let channelSettingsVC = SBUViewControllerSet.GroupChannelViewController(channelUrl: {CHANNEL_URL})

// The `headerComponent` in `SBUGroupChannelSettingsViewController` will now use `customHeader` as the default value.
  1. Change the module component in SBUGroupChannelSettingsViewController.
let channelSettingsVC = SBUViewControllerSet.GroupChannelViewController(channelUrl: {CHANNEL_URL})
channelSettingsVC.headerComponent = CustomHeader()

Note: To learn more about the methods of SBUGroupChannelSettingsModule, go to the API reference page.

View model

In order to use a customized view model or customize the existing view model's event delegate, you must override the view controller.

  1. Use a customized view model.
class CustomViewController: SBUGroupChannelSettingsViewController {
    override func createViewModel(channel: BaseChannel? = nil, channelURL: String? = nil) {
        // Set `viewModel` to the `CustomViewModel` object.
        self.viewModel = CustomViewModel()

        // Implement your code here.
    }
}
  1. Customize the view model's event delegate.
extension CustomViewController: SBUGroupChannelSettingsViewModelDelegate {
    override func baseChannelSettingsViewModel(
        _ viewModel: SBUBaseChannelSettingsViewModel,
        didChangeChannel channel: BaseChannel?,
        withContext context: MessageContext
    ) {
        // Implement your code here.
    }

    // Or override other delegate functions.
}