The number of unread messages from xmpp ios

I am developing a chat application using XMPPFrameWork. Everything works fine, but I'm stuck in getting the number of unread messages. I have to show the   tableViewnumber of posts that are not open yet. How can I continue, have any ideas? I tried to show mostRecentMessage, but it didn’t work. Any help would be appreciated. Thank.

+4
source share
1 answer

XMPP has an attribute called "unread messages" in "XMPPUserCoreDataStorageObject". Pass the "jid" FROM to get the corresponding user object, and add the value "unreadMessages" below in the Appdelegate application.

 - (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message  

and update it again in the same db.Like,

XMPPUserCoreDataStorageObject *user = [self.xmppRosterStorage userForJID:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@", [[[message fromStr] componentsSeparatedByString:@"/"]objectAtIndex:0] ]]
                                                                          xmppStream:self.xmppStream
                                                                managedObjectContext:[self managedObjectContext_roster]];

    NSNumber *number = user.unreadMessages;

    int value = [number intValue];

    number = [NSNumber numberWithInt:value + 1];

    user.unreadMessages = number;

Then use the code above in any view manager to get an unread number of messages.

0
source

All Articles