0

I am facing issue in fetching all registered users in XMPP ios project. I am using openfire.

Below are the code i am using but it always gives me zero in the arraylist.:-

- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
    NSXMLElement *queryElement = [iq elementForName: @"query" xmlns: @"jabber:iq:roster"];
    if (queryElement)
    {
        NSArray *itemElements = [queryElement elementsForName: @"item"];
        NSMutableArray *mArray = [[NSMutableArray alloc] init];
        for (int i=0; i<[itemElements count]; i++)
        {
            NSString *jid2=[[[itemElements objectAtIndex:i] attributeForName:@"jid"] stringValue];
            [mArray addObject:jid2];
        }
        NSLog(@"didReceiveIQ Array======%@",mArray);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"FriendRequestSend" object:nil];
    }
    return NO;
}

Though i can see 3 users in the browser.Please check the image Note: I had seen the post iOS XMPP framework get all registered users but it does not work.

Please help me and advice me there is mistake in the code

Community
  • 1
  • 1
Developer
  • 287
  • 1
  • 3
  • 12
  • The code you posted above gets the contacts that have been added to your roster, not all registered users. The question you linked to asks about how to do this with ejabberd. The way to do it with Openfire is probably different. – legoscia Feb 01 '16 at 11:13
  • @legoscia thanks for the reply. Can you guide me the way to implement this with openfire Please. – Developer Feb 02 '16 at 05:04

2 Answers2

0

If you are able to make changes in Openfire, You can develop a servlet (http service) in admin app which will simply return all users from ofUser table.
Or a custom packet, if you want to use XMPP.

0

I was working on getting all registered users from openfire into my app. After trying a lot i got a solution for getting all the registered users... here's the code :

- (void)getAllRegisteredUsers {

    NSError *error = [[NSError alloc] init];
    NSXMLElement *query = [[NSXMLElement alloc] initWithXMLString:@"<query xmlns='jabber:iq:roster'/>" error:&error];
    XMPPIQ *iq = [DDXMLElement elementWithName:@"iq"];
    [iq addAttributeWithName:@"type" stringValue:@"get"];
    [iq addAttributeWithName:@"none" stringValue:@"ANY_ID_NAME"];
    [iq addAttributeWithName:@"both" stringValue:@"ANY_ID_NAME"];
    [iq addChild:query];
    [xmppStream sendElement:iq];
}

- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{

    NSXMLElement *queryElement = [iq elementForName: @"query" xmlns: @"jabber:iq:roster"];

    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];
        }
        NSLog(@"%@",mArray);
    }
    return YES;
}

This worked for me, hope it will work for others as well... :)

iOS_MIB
  • 1,885
  • 13
  • 24