for my IOS Chatting Application i am using Openfire Server, i am retrieving particular user friends list but now i want to retrieve all registered users from Openfire Server. Please help me out and thanks in advance.
Asked
Active
Viewed 2,595 times
2 Answers
5
Finally I found the alternative answer for this by searching users using their username:
1.for every contact i am adding emailid username@domainname like this.
2.in the place searchstring if we use domainname then we will get all registered users.
//Request
- (void)getDetailsofRegisteredUser {
//To Search Peticular User either by using their name, email or username
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"]];
//Here in the place of SearchString we have to provide registered user name or emailid or username(if it matches in Server it provide registered user details otherwise Server provides response as empty)
NSXMLElement *search = [NSXMLElement elementWithName:@"field"];
[search addAttributeWithName:@"var" stringValue:@"search"];
[search addChild:[NSXMLElement elementWithName:@"value" stringValue:[NSString stringWithFormat:@"%@", SearchString]]];
[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.%@",DOMAIN_NAME]];
[iq addAttributeWithName:@"from" stringValue:userBare1];
[iq addChild:query];
[[[self appDelegate] xmppStream] sendElement:iq];
}
//We will get response here
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
NSLog(@"searched format %@", iq);
}
peterh
- 11,875
- 18
- 85
- 108
Anjaneyulu Battula
- 1,910
- 16
- 33
-
Hi anjaneyulu, thanks for the answer it helped me a lot. I got data in iq, now I need help to parse the response from server. I dont know how to do it. Please help me. – shyam.y Nov 19 '14 at 09:37
-
I got all the users from server. But can not get it in array from xml format.If anyone can help. then please do the needful.I will be happy to appreciate it – Dimple Oct 03 '16 at 11:03
-1
- (void)getAllRegisteredUsers {
NSError *error = [[NSError alloc] init];
NSXMLElement *query = [[NSXMLElement alloc] initWithXMLString:@"<query xmlns='http://jabber.org/protocol/disco#items' node='all users'/>"
error:&error];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get"
to:[XMPPJID jidWithString:@"DOMAIN"]
elementID:[xmppStream generateUUID] child:query];
[xmppStream sendElement:iq];
}
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
NSXMLElement *queryElement = [iq elementForName: @"query" xmlns: @"http://jabber.org/protocol/disco#items"];
if (queryElement) {
NSArray *itemElements = [queryElement elementsForName: @"item"];
NSMutableArray *mArray = [[NSMutableArray alloc] init];
for (int i=0; i<[itemElements count]; i++) {
NSString *jid=[[[itemElements objectAtIndex:i] attributeForName:@"jid"] stringValue];
[mArray addObject:jid];
}
}
Rahul Patel
- 5,858
- 6
- 46
- 72
-
hi Rahul ,I am not getting any registered users who are there in server.Can you please say something. – Romance Dec 16 '13 at 06:53
-
I am using correct DOMAIN,my doubt is in server there are 20 users ,and one user is my friend remaining 19 users are there in server.I need all users who are there in server,I am not asking about group chat,i am Asking normal chat,peer to peer. – Romance Dec 16 '13 at 06:58
-
-
@Romance also can you please confirm what JID have you set in the query?? – Singh Mar 02 '14 at 07:54
-
-
@exceptionx0000f : I have not access of my system to validate code but can you please check http://forum.ag-software.net/thread/1059-Is-it-possible-to-get-the-list-of-all-registered ? it might help you – Rahul Patel Mar 04 '14 at 13:30
-
@RahulPatel Thanks Rahul for your Reply, but it is not working for me.May be this code may not working with Openfire Server. – Anjaneyulu Battula Mar 14 '14 at 11:55