Create a Channel

To create a new channel using the SDK, you need to create at least 2 Participant instances with the participant user IDs and pass them as an array to either to createDirectMessageChannel() or createGroupMessageChannel() function depending on the number of participants you have.

Let’s initialise two participants and create a direct message channel.

let stan = Participant(id: "csrCy-SJL3u-8AKMT-Wqv6y")
let rahul = Participant(id: "E3CAM-jjw8A-WeqDe-cWFe7")

Substitute the user IDs with your own user IDs here.

Now, call the function:

appDelegate.mitter.channels.createGroupMessageChannel(participants: [stan, rahul]) { result in
            switch result {
            case .success(let channelId):
                print("New channel created: \(channelId)")
            case .error:
                print("Couldn't create channel")
            }
        }

Run your project and now you should see a New channel created message in your console log along with the ID of the newly created channel.

Note down the ID because we’ll use it to send and receive some messages

Last updated