let guid = "cometchat-guid-11"let password: String? = nil // mandatory in case of password protected group typeCometChat.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)})
Report incorrect code
Copy
Ask AI
NSString *guid = @"cometchat-guid-101";NSString *password = nil; // mandatory in case of password protected group type[CometChat joinGroupWithGUID:guid groupType:groupTypePublic password:password onSuccess:^(Group * group) { NSLog(@"Group joined successfully: %@", [group stringValue]);} onError:^(CometChatException * error) { NSLog(@"Group joining failed with exception: %@", [error errorDescription]);}];
Sample Payload - Join Public Group
Request Parameters:
Parameter
Type
Description
GUID
String
Unique group identifier. Example: "cometchat-guid-1"
Human-readable error message. Example: "The private groups cannot be joined. Users need to be added to such groups."
Private groups cannot be joined directly. Users must be added by an admin or owner.
Once you have joined a group successfully, you can send and receive messages in that group.
CometChat keeps a track of the groups joined and you do not need to join the group every time you want to communicate in the group. You can identify if a group is joined using the hasJoined parameter in the Group object.
In other words, as a recipient, how do I know when someone joins a group?To receive Real-Time Events for the same, you need to implement the onGroupMemberJoined() method of the CometChatGroupDelegate.
@interface ViewController ()<CometChatGroupDelegate>@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [CometChat setGroupdelegate:self];}- (void)onMemberAddedToGroup:(Action *)action addedBy:(User * _Nonnull)addedBy addedUser:(User * _Nonnull)addedUser addedTo:(Group * _Nonnull)addedTo { // When any member is added in the group this function will be called}@end
Sample Payload - onGroupMemberJoined Event
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberJoined(action:joinedUser:joinedGroup:)ActionMessage Object:
In other words, as a member of a group, how do I know if someone joins the group when my app is not running?When you retrieve the list of previous messages if a member has joined any group that the logged-in user is a member of, the list of messages will contain an Action message. An Action message is a sub-class of BaseMessage class.For the group member joined event, in the Action object received, the following fields can help you get the relevant information: