gpt4 book ai didi

ios - XMPPFramework - 如何将用户添加到 MUC 房间

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:57 24 4
gpt4 key购买 nike

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

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

谢谢。瓦兹

最佳答案

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

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

希望这对您有所帮助。

关于ios - XMPPFramework - 如何将用户添加到 MUC 房间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18556092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com