In-app Chat Kit
  • iOS : Swift
  • Android
  • Flutter
  • React Native
  • Overview
  • Quick start
  • UI components
    • Overview
    • Conversation component
    • Message component
  • Advanced features
  • Documentation
  • In-app Chat UIKit
  • UI components
  • Message component

Message component

Last updated:2023-06-05 10:36

The message component of the In-app Chat Kit provides the message list and message transmission features.

  • Message list: Allow you to view the message history of a chat.
  • Message transmission: Allow you to send or receive one-to-one messages and group messages.

Integrate the message component into your project

Prerequisites

Integrate the In-app Chat Kit SDK into your project (finished the initialization and login are required). For more information, see Quick start.

Add the message component

  1. Import the In-app Chat Kit module.
import UIKit
import ZIMKit

/// your ViewController.swift
class ViewController: UIViewController {

}
  1. Display the message component.
import UIKit
import ZIMKit

/// your ViewController.swift
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    /// Call the following method to display the message component after login succeeded.
    func showMessageListVC() {
        let conversationID = "xxx"  // Conversation ID. For one-on-one chats, it refers to the peer's userID. For group chats, it refers to the GroupID. 
        let type: ConversationType = .peer // Conversation type (one-on-one chats or group chats). 
        let messageVC = ZIMKitMessagesListVC(conversationID: conversationID, type: type)
        navigationController?.pushViewController(messageVC, animated: true)
    }
}

Customize features

If the default message-relevant features and behaviors don't fully meet your needs, we allow you to flexibly customize those through the config we mentioned in this section.

Custom header bar

To customize buttons on the NavigationBar, you can implement the delegate ZIMKitMessagesListVCDelegate.

For example, when you want to add a "Start a call" button on the upper right of the message list (ZIMKitMessagesListVC). To learn more details, see Use with the Call Kit.

import UIKit
import ZIMKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        let messageVC = ZIMKitMessagesListVC(conversationID: "conversationID", type: .peer)
        messageVC.delegate = self

        // Set up and listen to the messageDelegate to receive message relevant notifications if you integrated the ZIMKitConversationListVC
        let conversationVC = ZIMKitConversationListVC()
        conversationVC.messageDelegate = self
    }
}

extension ViewController: ZIMKitMessagesListVCDelegate {

    /// Callback for get the HeaderBar
    /// - Parameter messageListVC: ZIMKitMessagesListVC
    /// - Returns: ZIMKitHeaderBar: Include the leftItems, rightItems, and titleView
    func getMessageListHeaderBar(_ messageListVC: ZIMKitMessagesListVC) -> ZIMKitHeaderBar? {

        // Get the conversation ID via the messageListVC.conversationID 
        // Get the conversation name via the messageListVC.conversationName 
        // Get the conversation type (one-on-one or group chat) via themessageListVC.conversationType 

        let customBarButtonItem = UIBarButtonItem(title: "Custom", style: .plain, target: self, action: #selector(customButtonTapped))

        let headerBar = ZIMKitHeaderBar()
        headerBar.rightItems = [customBarButtonItem]
        headerBar.titleView = UIView()

        return headerBar
    }
}
Custom input bar

To customize buttons on the input bar, configure the InputConfig:

  • showVoiceButton: Whether to display the voice button
  • showEmojiButton: Whether to display the Emoji button
  • showAddButton: Whether to display the Add button

Here's the reference code:

let inputConfig = InputConfig(showVoiceButton: true,
                              showEmojiButton: true,
                              showAddButton: false)

let messageListVC = ZIMKitMessagesListVC(conversationID: conversation.id,
                                         type: conversation.type,
                                         conversationName: conversation.name,
                                         inputConfig: inputConfig)
Page Directory