我正在使用xmpp ejabberd开发聊天应用程序。我想开发类似于什么应用程序的XMPP群聊。 XMPP组聊天设置在我的XMPP服务器上完成。我成功地创造了房间和房间。加入房间。但我想要我加入的房间。我使用以下iq从服务器
获取组列表NSString* server = @"conference.test.com";
XMPPJID *serverJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:serverJID];
[iq addAttributeWithName:@"from" stringValue:[[APP_DELEGATE xmppStream] myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[APP_DELEGATE xmppStream] sendElement:iq];
从上面的代码我从我的服务器获取组列表但我想要我加入的组列表或我收到邀请的组。
创建代码&加入房间如下
-(void) CreateRoom:(NSString *)roomJid {
static dispatch_once_t queueCreationGuard;
static dispatch_queue_t queue;
dispatch_once(&queueCreationGuard, ^{
queue = dispatch_queue_create("com.something.myapp.backgroundQueue", 0);
});
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:roomJid];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:queue];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self
delegateQueue:queue];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"0"];
[xmppRoom joinRoomUsingNickname:[self xmppStream].myJID.user
history:history
password:nil];
}
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
NSLog(@"Room Created");
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
NSLog(@"Room Joined");
}
如果有人有解决方案,请回答问题。感谢
答案 0 :(得分:0)
您可以使用此:( Swift 3.0)
var muc = XMPPMUC(dispatchQueue: DispatchQueue.main)
muc?.activate(stream) //Here stream is the XMPPStream
muc?.addDelegate(self, delegateQueue: DispatchQueue.main)
muc?.discoverRooms(forServiceNamed: "conference.localhost")
或者您可以使用此:
let xmlstring: String = String("<query xmlns='http://jabber.org/protocol/disco#items'/>")
let newQuery = try! DDXMLElement(xmlString: xmlstring)
let newIq = XMPPIQ(type: "get", to: XMPPJID(string:"conference.localhost"), elementID: stream.generateUUID(), child: newQuery)
stream.send(newIq)