0

Is there a way i can get all users that are registered using InBand registration on openfire server. I have checked the following links :

1.ios-xmpp-framework-get-all-registered-users

2.ios-xmpp-framework-with-openfire-server-get-all-registered-users

but those links dont help . If i use the following code that is used in above links :

- (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];
}

i get 503 error code with service unavailable message . Can any one tell me if i am doing something wrong at the iOS end or the server is missing something. All suggestions are welcome.

Community
  • 1
  • 1
Singh
  • 2,151
  • 3
  • 15
  • 30
  • As an aside you don't need `NSError *error = [[NSError alloc] init];` a simple `NSError *error;` is enough. The point of passing a pointer by indirection is so that the method can return an object using the pointer, you aren't passing something that the method is going to use. – Abizern Mar 05 '14 at 09:52

2 Answers2

0

need to change "DOMAIN" to your server name

naresh
  • 627
  • 1
  • 7
  • 28
0

I was working on getting all registered users from openfire into my app. I tried all the methods from the mentioned links but non helped me! 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
  • I think this will only work for getting all your rosters. This won't work for getting all registered users on openfire server. If you don't have any rosters then your `itemElements` will return nil. – iPeter May 17 '16 at 13:52