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

标签 ios objective-c xmpp xmppframework

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

_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/

相关文章:

ios - UIKit Dynamics 和 CALayers 与 UIView 分离

ios - 无法通过 CocoaPods 安装 pod (Mixpanel) - 编译失败(找不到文件) - 桥接头问题?

ios - 使用-[UIScrollView zoomToRect :animated:] 的单元测试方法

ios - 如何从 iOS 中的 XMPP 服务器删除特定用户的聊天记录?

ios - 如何在ios swift中实时更新单元格内容时实时更新tableview单元格内容

ios - 如何让 iPhone 屏幕在视频通话期间保持亮着

ios - 如果我在聊天应用程序(WhatsApp 之类的应用程序)中使用 VOIP 功能,Apple 会拒绝我的应用程序吗

linux - Openfire xmpp 服务器和 Spectrum 2 IM Solaris 和 Linux

ios - 让 UIView drawRect 出现在后台线程中

c++ - Xcode 7 和 openCV(无 Swift): Core. hpp header 必须编译为 C++