I am creating a XMPP chat app on iOS. I am trying to do is search user over XMPP. I checked the opernfire server and it has the search plugin enabled. I gone through XEP:0055 and found the stanza.
2 Answers
0
votes
See http://xmpp.org/extensions/xep-0055.html for reference on the format of the XML you should send and expect to receive back.
If you are trying to perform a search, here is an example for searching for a user by email address
NSString *bareJID = [self.xmppStream.myJID bare];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:search"];
NSXMLElement *email = [NSXMLElement elementWithName:@"email" stringValue:searchQuery];
[query addChild:email];
NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
[iq addAttributeWithName:@"id" stringValue:@"search2"];
[iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",self.xmppStream.myJID.domain]];
[iq addAttributeWithName:@"from" stringValue:bareJID];
[iq addAttributeWithName:@"xml:lang" stringValue:@"en"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
In your callback for xmppStream:didReceiveIQ: you will receive a response from the server, with the same id you specified above (in this case 'search2'). This will be an XML response, as indicated on the initial URL I mentioned for the XEP-0055 reference page, and you can parse it out accordingly.
0
votes
You can go http://blog.csdn.net/dangfm/article/details/36185879,and follow '搜索关键词' to assemble XML(iq),then _xmppStream send it(iq).