0
votes

I am doing an XMPP iPhone chat application for the first time (using XMPP framework from gitHub). On that I can able to send and receive messages, but my problem is :

Now I am on the chatting page, on that I have used a method to fetch all the archived messages from XMPPMessageArchivingCoreDataStorage and displaying it to the user. When a new message arrives "xmppStream: didReceiveMessage:" method will get called and on that I have posted a notification. Receiver of that notification is set on the chatting page. So when a new message notification arrives I use the same previous method to fetch the archived messages and then display it to the user. I have done this for showing the new message to the user. But my problem is that when Message 1 arrives it's not listing, then Message 2 arrives Message 1 listing, when Message 3 arrives Message 1 and 2 are listing and so on. But some times it works fine.

My doubts are :

  1. Is this the correct way to display new messages ?
  2. If yes, why the last message is not archiving some times ?

Thanks in advance...

2

2 Answers

0
votes

You mean that all message is received ? If that's it,you just add all messages into a List and then inform the Table to update the data.To make sure it work,Add a dispatch_async in your code.

0
votes

No need for posting notifications when a new message arrived. For that we can use NSFetchedResultsController.

I have fixed the issue by using NSFetchedResultsController for managing the XMPPMessageArchivingCoreDataStorage and tableview.

See more about NSFetchedResultsController