如何使用xmpp ios加入组并获取已存在的组列表

时间:2014-09-25 05:27:11

标签: ios iphone xmpp chat xmppframework

我使用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!"];
}

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

2 个答案:

答案 0 :(得分:2)

您可以使用此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];

}

答案 1 :(得分:0)

    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)