XMPPFramework - 如何将用户添加到MUC聊天室

3

我正在创建一个群聊应用程序。使用以下代码可以创建群组。

_xmppRoomStorage = [[XMPPRoomCoreDataStorage alloc]init];
   XMPPJID *roomJID = [XMPPJID jidWithString:@"room1@conference.abc.biz"];
   _xmppRoom =[[XMPPRoom alloc] initWithRoomStorage:_xmppRoomStorage jid:roomJID];
   [_xmppRoom              activate:_xmppStream];
   [_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
   xmppRoom joinRoomUsingNickname:_userNameEdit.text history:nil];

现在我需要在这个群组中添加一些用户。请问有人能告诉我如何添加或邀请多个用户到这个群组吗?

我还有一个问题,当第一个群组处于活动状态时,无法创建第二个房间。当我尝试创建第二个房间时,会出现以下错误:

"XMPPRoom[room2@conference.abc.biz] - 已经在创建/加入/已加入房间时无法再次创建/加入房间"

谢谢。 Vaz


我已经解决了这个问题...... - Vaz
你能分享一下解决方案吗?我遇到了同样的问题。 - Azerue
1个回答

2
我通过以下方式解决了这个问题:
  1. Create the room first

    -(void) CreateRoom
    {
        XMPPJID *roomRealJid = [XMPPJID jidWithString:jidRoom];// Room name ex. abc@conference.xyz.biz
        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]];
    }
    
  2. 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"];
            }
        }
    }
    
希望这能帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接