【问题标题】:How to join group and get list of already existing group using xmpp ios如何使用 xmpp ios 加入群组并获取现有群组的列表
【发布时间】:2014-11-19 18:57:31
【问题描述】:

我正在使用 xmpp jabber 客户端实现群聊。我正在使用以下代码成功创建组。

 -(void) CreateRoom { 
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init]; 
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString    stringWithFormat:@"NewGroup@conference.%@",JABBER_DOMAIN_NAME]];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:appDelegate.xmppStream];
[xmppRoom addDelegate:self
    delegateQueue:dispatch_get_main_queue()];

[xmppRoom joinRoomUsingNickname:appDelegate.xmppStream.myJID.user
                    history:nil
                   password:nil];
}
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
 NSLog(@"xmppRoomDidCreate");
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
NSLog(@"xmppRoomDidJoin");
[sender fetchConfigurationForm];

[sender inviteUser:[XMPPJID jidWithString:@"Test1"] withMessage:@"Greetings!"];
[sender inviteUser:[XMPPJID jidWithString:@"Test2"] withMessage:@"Greetings!"];
}

所以请建议我如何加入用户获取现有组的列表以进行进一步实施.. 谢谢,

【问题讨论】:

    标签: ios iphone xmpp chat xmppframework


    【解决方案1】:

    你可以通过这个protocol: http://jabber.org/protocol/disco#items获取你MUC服务器上的组列表:

    - (void) getListOfGroups
    {
        XMPPJID *servrJID = [XMPPJID jidWithString:CONFERENCE_ROOM_SERVER];
        XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:servrJID];
        [iq addAttributeWithName:@"from" stringValue:[[self xmppStream] myJID].full];
        NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
        [query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
        [iq addChild:query];
        [[self xmppStream] sendElement:iq];
    
    }
    

    【讨论】:

    • 您好,尝试与以下 url stackoverflow.com/questions/19268629/… 相同的代码,但我无法获取已创建的房间列表。在委托 mthoed - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{} 以及如何在此方法中处理响应。
    • 我可以成功获取会议室列表。但是我可以将此列表保存在 xmpp 的 coredaatastorage 中或解析以供进一步使用。或者有没有办法处理组列表以供离线访问。请分享帮助我离开这里的代码或链接...
    • @BalKrishanYadav 能否请您提供获取组列表的代码。上面的代码不起作用。
    • @BalKrishanYadav 你能解释一下如何获得组列表吗?我也试过了,但一无所获。请帮助我。
    【解决方案2】:
        let server: String = "conference.iamhosting"
        let servrJID: XMPPJID = XMPPJID.jidWithString(server)
        let iq: XMPPIQ = XMPPIQ.iqWithType("get", to: servrJID)
        iq.addAttributeWithName("id", stringValue: "chatroom_list")
        iq.addAttributeWithName("from", stringValue: stream.myJID.bare())
        let query = DDXMLElement.elementWithName("query")
        query.addAttributeWithName("xmlns", stringValue: "http://jabber.org/protocol/disco#items")
        iq.addChild(query as! DDXMLElement)
        stream.addDelegate(self, delegateQueue: dispatch_get_main_queue())
        stream.sendElement(iq)
    

    【讨论】:

    • 添加一些解释。
    猜你喜欢
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 2013-06-22
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多