Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Join a public group
CometChat.joinGroup(GUID: "GUID", groupType: .public, password: nil,
    onSuccess: { group in }, onError: { error in })

// Join a password-protected group
CometChat.joinGroup(GUID: "GUID", groupType: .password, password: "password123",
    onSuccess: { group in }, onError: { error in })

// Listen for member joined events via CometChatGroupDelegate
func onGroupMemberJoined(action: ActionMessage, joinedUser: User, joinedGroup: Group) { }
Join a group to start sending and receiving messages in it. Public groups can be joined freely, password groups require the correct password, and private groups require an admin to add you (no direct join).

Join a Group

Use joinGroup() to join a group.
let guid = "cometchat-guid-11"
let password: String? = nil // mandatory in case of password protected group type

CometChat.joinGroup(GUID: guid, groupType: .public, password: nil, onSuccess: { (group) in
    print("Group joined successfully. " + group.stringValue())
}, onError: { (error) in
    print("Group joining failed with error:" + error!.errorDescription)
})
ParameterDescription
GUIDThe GUID of the group to join
groupType.public, .password, or .private
passwordRequired for password-protected groups
Once joined, you can send and receive messages in the group. CometChat tracks joined groups — you don’t need to rejoin each session. Check hasJoined on the Group object to verify membership. The method returns a Group object with hasJoined set to true.

Real-time Group Member Joined Events

Register a CometChatGroupDelegate to receive events when members join.
class ViewController: UIViewController, CometChatGroupDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        CometChat.groupdelegate = self
    }
    
    func onGroupMemberJoined(action: ActionMessage, joinedUser: User, joinedGroup: Group) {
        print("\(joinedUser.name ?? "") joined \(joinedGroup.name ?? "")")
    }
    
    func onMemberAddedToGroup(action: ActionMessage, addedBy: User, addedUser: User, addedTo: Group) {
        print("\(addedUser.name ?? "") was added to \(addedTo.name ?? "")")
    }
}
Always remove group listeners when they’re no longer needed (e.g., on view dismissal). Failing to remove listeners can cause memory leaks and duplicate event handling.

Missed Group Member Joined Events

When fetching message history, join events appear as Action messages with:
  • action"joined"
  • actionByUser who joined
  • actionForGroup that was joined

Next Steps

Leave a Group

Allow members to leave a group

Retrieve Group Members

Fetch the list of members in a group

Send Messages

Send messages to group conversations

Add Members

Programmatically add members to a group