How to add user to existing ROOM in XMPP iOS?

527 views Asked by At

I am working in XMPP chat module. I have created group yesterday, Now I want to add some more member in this group. What will be the process to add member in existing group.

Here is my code to create group:

XMPPJID *roomJID = [XMPPJID jidWithString:@"[email protected]"];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *newxmppRoom = [[XMPPRoom alloc]
            initWithRoomStorage:roomMemoryStorage
            jid:roomJID
            dispatchQueue:dispatch_get_main_queue()];
[newxmppRoom activate:xmppStream];
[newxmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[newxmppRoom joinRoomUsingNickname:@"MY_NICKNAME" history:nil];

Should I have to write above code every time when I want to add user in room?

1

There are 1 answers

0
James Andrews On

Yes, all this code is required to join a room. To invite a user, you should use the method:

XMPPJID * userID = [XMPPJID jidWithString:user.entityID];
[room inviteUser:userID withMessage:@""];

Then in the callback:

- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *)roomJID didReceiveInvitation:(XMPPMessage *)message {
    // User your code here to join
}