0

I'm developing an app with PubNub iOS SDK that works great, but there is one annoying issue with the History API.

I have to list the message history in multiple view controllers, that works well, but I have to wait 2-3 second for the messages every time I open a new view. Is there any common practice to avoid this?

I'm using the requestHistoryForChannel: with block in every view controllers viewDidLoad. I know it's a problem because every time I open a new view the client needs to reconnect and retrieve the history again, but i could not find a better solution. I have to download the same channel's history in every view, so the content is always the same, therefore I think it's absolutely possible to fetch the messages when I launch the app and use that data across the whole app and don't wait, but I have no idea how to do it.

Prophet
  • 32,350
  • 22
  • 54
  • 79
cimp23
  • 49
  • 5

1 Answers1

2

Actually, this is not an issue of PubNub SDK. I can suggest you to create data model which will manage caching for you and you will pull history only then when it will be required or you think that you should pull it out.

As for reconnection: PubNub SDK maintain few TCP connections all the time and doesn't teardown them till application suspension or disconnect request. The fact, that it took 2 seconds for you mean that there is significant amount of data, slow connection or both cases. You can also limit amount of messages which you want to receive using limit parameter or can slice messages using startDate and endDate parameters (there is a lot of designated methods related to history API).

Serhii Mamontov
  • 4,942
  • 22
  • 26
  • Thank you, i will try to limit the messages first. Actually i'm using some observer methods for example the `addClientConnectionStateObserver:`, these methods can affect the speed or doesn't matter? – cimp23 Jun 23 '14 at 12:46
  • 1
    @cimp23 this is observer, it is responsible only for event delivering. btw, you can use it to register few observers on history processing completion (if you need to). – Serhii Mamontov Jun 23 '14 at 13:43