简体   繁体   中英

fetch all registered users in xmpp ios in openfire

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. 请检查图像 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

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.

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... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM