0
votes

I have come across a chatting app.

As I haven't worked with the Ejabberd server before, I am stuck with one of the issues of fetching the roster list.

I am getting the list as nil every time, even if the contacts list is available on the server.

Below are the methods that I use to get the roster list.

Below is how I fetch the contacts:

Here in this code, I every time get the query list as nil

-(void)fetchContacts {
    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 addChild:query];
    [self.xmppStream sendElement:iq];
}

Did receive IQ method:

- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{ 
      NSXMLElement *query = [iq elementForName: @"query" xmlns: @"jabber:iq:roster"];
      if (query) {
         NSArray *item = [query elementsForName: @"item"];
         NSMutableArray *arr = [[NSMutableArray alloc] init];
         for (int i=0; i<[item count]; i++) {
             NSString *jid=[[[item objectAtIndex:i] attributeForName:@"jid"] stringValue];
             [arr addObject:jid];
         }
         [userDefault setValue:arr forKey:@"contacts"];
         [userDefault synchronize];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"ContactsData" object:nil];
      }
      return YES; 
}

I've tried many solutions for this from the stack overflow but nothing worked for me.

Thanks!

1

1 Answers

0
votes

Use a network traffic to capture what does your client send to ejabberd.

Then install a well-known XMPP client, for example Gajim, Psi, Tkabber... Then perform the same operation using that client, and capture again the XML that the client sends.

Compare this with the XML sent by your client, hopefully you will see some relevant change (and also other irrelevant differences).