IOS XMPP, search for users by username

The first time I'm working on the XMPP Framework on iOS. Can anyone help finding users using their username.

I tried the method described in the link below. But no luck.

iOS XMPP framework gets all registered users

Thanks in advance.

+4
source share
2 answers

I finally get it. I did it myself.

NSString *userBare1 = [[[[self appDelegate] xmppStream] myJID] bare]; NSXMLElement *query = [NSXMLElement elementWithName:@"query"]; [query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:search"]; NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"]; [x addAttributeWithName:@"type" stringValue:@"submit"]; NSXMLElement *formType = [NSXMLElement elementWithName:@"field"]; [formType addAttributeWithName:@"type" stringValue:@"hidden"]; [formType addAttributeWithName:@"var" stringValue:@"FORM_TYPE"]; [formType addChild:[NSXMLElement elementWithName:@"value" stringValue:@"jabber:iq:search" ]]; NSXMLElement *userName = [NSXMLElement elementWithName:@"field"]; [userName addAttributeWithName:@"var" stringValue:@"Username"]; [userName addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1" ]]; NSXMLElement *name = [NSXMLElement elementWithName:@"field"]; [name addAttributeWithName:@"var" stringValue:@"Name"]; [name addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]]; NSXMLElement *email = [NSXMLElement elementWithName:@"field"]; [email addAttributeWithName:@"var" stringValue:@"Email"]; [email addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]]; NSXMLElement *search = [NSXMLElement elementWithName:@"field"]; [search addAttributeWithName:@"var" stringValue:@"search"]; [search addChild:[NSXMLElement elementWithName:@"value" stringValue:searchField]]; [x addChild:formType]; [x addChild:userName]; //[x addChild:name]; //[x addChild:email]; [x addChild:search]; [query addChild:x]; NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"]; [iq addAttributeWithName:@"type" stringValue:@"set"]; [iq addAttributeWithName:@"id" stringValue:@"searchByUserName"]; [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",[self appDelegate].hostName ]]; [iq addAttributeWithName:@"from" stringValue:userBare1]; [iq addChild:query]; [[[self appDelegate] xmppStream] sendElement:iq]; 
+7
source

correct answer.

following code

 [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",[self appDelegate].hostName ]]; 

means

 XMPPJID *myJID = [[[self appdelegate] xmppStream] myJID]; [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",myJID.domain]]; 
0
source

Source: https://habr.com/ru/post/1502845/


All Articles