Reputation: 79
I am creating group chat app. I am able to create the group with below code.
_xmppRoomStorage = [[XMPPRoomCoreDataStorage alloc]init];
XMPPJID *roomJID = [XMPPJID jidWithString:@"[email protected]"];
_xmppRoom =[[XMPPRoom alloc] initWithRoomStorage:_xmppRoomStorage jid:roomJID];
[_xmppRoom activate:_xmppStream];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppRoom joinRoomUsingNickname:_userNameEdit.text history:nil];
but now I need to add some users to this group. Can any one please let me know how to add or invite multiple users to this group.
I have one more problem. not able to create 2nd room when 1st group is active. When I try to create 2nd room it gives below error
"XMPPRoom[[email protected]] - Cannot create/join room when already creating/joining/joined"
Thanks. Vaz
Upvotes: 3
Views: 2064
Reputation: 79
I fixed this issue by doing as follows:
Create the room first
-(void) CreateRoom
{
XMPPJID *roomRealJid = [XMPPJID jidWithString:jidRoom];// Room name ex. [email protected]
XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[[self appDelegate] xmppRoomStorage] jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
[newXmppRoom activate: [[self appDelegate] xmppStream]];
[newXmppRoom fetchConfigurationForm];
[newXmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];
[newXmppRoom joinRoomUsingNickname:nickName history:nil password:[[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword]];
}
Send invitations
// Once the room created, we get some responses from server.
// One of them is "didFetchModeratorsList".
- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items
{
DDLogInfo(@"%@: %@ --- %@", THIS_FILE, THIS_METHOD, sender.roomJID.bare);
if (check the flag for room create and invite) // This has to be done only when we intended
{
NSArray* users = list of users we need to invite.
if (users.count > 0)
{
for (int i=0; i< users.count; i++)
{
NSString *jid = [NSString stringWithFormat:@"%@@xyz.biz", [users objectAtIndex:i]];
XMPPJID *xmppJID=[XMPPJID jidWithString:jid];
[sender inviteUser:xmppJID withMessage:@"Join Group."];
}
[sender sendMessageWithBody:@"Hi All"];
}
}
}
Hope this helps.
Upvotes: 2