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] - 已经创建/加入/加入时无法创建/加入房间”

谢谢。瓦兹

4

1 回答 1

2

我通过以下方式解决了这个问题:

  1. 首先创建房间

    -(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. 发送邀请

    // 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"];
            }
        }
    }
    

希望这可以帮助。

于 2013-12-24T07:50:55.513 回答