Updating / Downloading Messages in the background?

How does Sendbird handle updating messages in the background? We can receive a push notification in the background, but trying to add the updated last message to the channel doesn’t work when we try to use SendbirdSyncManager after receiving the new message.

The goal we’re trying to accomplish is caching messages and files associated with them the second that a message comes in, even if the app is in the background. While documentation seems to hint that this is possible, we can’t get our shared instance of the SendBird client to call its delegate functions and update the cache. Thanks so much to anyone who can help.

1 Like

@Jay_S Hi, Could you share what platform are you working to get this accomplished? (i.e. JavaScript, iOS, Android)?

1 Like

Oh, my apologies, it’s with iOS.

Background sync is mentioned here, and maybe this is a very open ended question, but let’s say that we have a class with a shared instance, and all of the channels are accessed via SendbirdManager.shared.channels (SendbirdManager is a class that we wrote that conforms to Sendbird delegates, so we could update the channels no matter what view controller the user is on). Once the app is in the background, the shared instance of SendbirdManager is gone. The delegates from SendbirdSync do not get called in the background, they are only called when the app starts up again. We are not sure what to do to cache these incoming messages if the app is in the background but not fully quit. Is there a cache in SendbirdSync that we should be looking at?

To be more specific, when using Facebook Messenger, Telegram, iMessage, or WhatsApp, if the user receives a message then opens the app, the message is already there and the user doesn’t have to wait a couple of seconds for it to show up. We want to update the message collection in the background so when the user returns the message is already there and we don’t have the current delay of 1-2 seconds.

I have reached a solution after talking to SendBird support, thank you. The functionality I’m seeking is not possible with SendBird or most chat SDKs because that would require people staying connected to SendBird even when the app isn’t open, which could push the number of connected users up very quickly. The apps I listed above use a custom chat implementation, which makes it possible for them.

@Jay_S Hi Jay.

There is a workaround even though SendBird does not officially supports background fetching itself.

For instance, you can enable background fetching and remote notification capability for your iOS application. Then when you receive a push notification from Sendbird server, you can run background fetching and get messages (you can either fetch channel to get last message or get list of messages) through Sendbird SDK.

1 Like