【问题标题】:XMPPFramework - How to Add Users to MUC RoomXMPPFramework - 如何将用户添加到 MUC Room
【发布时间】:2013-09-04 13:14:37
【问题描述】:

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

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

谢谢。 瓦兹

【问题讨论】:

  • 我已经解决了这个问题......
  • 你能分享一下我实际上面临同样问题的解决方案

标签: ios objective-c xmpp xmppframework


【解决方案1】:

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

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2012-05-09
    • 1970-01-01
    • 2011-10-10
    • 2018-11-07
    • 2017-05-03
    • 2017-06-29
    • 2017-07-14
    • 2016-02-06
    相关资源
    最近更新 更多