1
votes

I am making a chat app with xmpp framework.

I have setup XMPPFramework in my project by referring this link:- http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190

I have problem to get presence of roster in did receive presence.

- (void)xmppStream:(XMPPStream )sender didReceivePresence:(XMPPPresence )presence
{

     DDLogVerbose(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, [presence fromStr]);
     presenceType = [presence type]; // online/offline
     //myUsername = [[sender myJID] user];
     presenceFromUser = [[presence from] user];
     //from = [[presence attributeForName:@"from"]stringValue];
     //type=[[presence attributeForName:@"type"]stringValue];
     NSLog(@"Present:%@",presenceType);
     NSLog(@"StatusUser:%@",presenceFromUser);

     [chlsttableview reloadData];

}

And in tableview I am showing presence of user as image of green or grey.

- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      cl=[tableView dequeueReusableCellWithIdentifier:@"chtlistprototype" forIndexPath:indexPath];

      cl.fnm.text=[arrname objectAtIndex:indexPath.row];
      cl.fmsg.text=[arrid objectAtIndex:indexPath.row];
      cl.dpimg.image=img;
      NSUInteger a=[arrid indexOfObject:cl.fmsg.text];
      NSNumber *x=[NSNumber numberWithInteger:a];
      if ([arrid containsObject:presenceFromUser]&&[presenceType isEqualToString:@"available"])
      {
          for (int i=0; i<arrid.count; i++)
          {
              // NSIndexPath *path=[NSIndexPath indexPathForRow:i inSection:0];
            if ([[arrid objectAtIndex:indexPath.row]isEqualToString:presenceFromUser])
            {
                 cl.stsimgvew.image=[UIImage imageNamed:@"green.png"];
            }

        /*NSString gt=[arrid objectAtIndex:indexPath.row];
         NSUInteger n=[arrid indexOfObject:gt];
         if (n==indexPath.row)
         {
         cl.stsimgvew.image=[UIImage imageNamed:@"green.png"];
         }*/

        }
   }
return cl;
}

So, my problem is that I am not getting proper presence image in tableview. I am getting one presence at a time and reloading table. If i have 5 friends then did receive presence method will call 5 time for presence and then presence image will display only of last user.

2
this is an example app which is completely working, go through this, it will help u a lot github.com/rayaleen/OpenFireClientAsad ali

2 Answers

1
votes

-You will get from presence id of user on xmpp , which you can reflect in ur online status of your code

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
    //XMPPPresence *online=[[XMPPPresence alloc]init];

    //[self xmppStream:xmppStream didReceivePresence:online];
    type=[[presence attributeForName:@"type"]stringValue];
    show_sts=[presence show];
    presenceFromUser = [[presence from] user];
}
0
votes

You can use a Wrapper written in Swift around the XMPPFramework, it will simplify the development of a basic chat app, you will be notified when the XMPPPresence changes and there is an end-to-end tutorial to get you there.

You can check it out here.