App stops working when IOS locked

Hi, when app is running on IOS and user locks their device, after around 5min when going back to the app everything is not working. When sending a message to the user they don’t receive it.

The user has to logout and log back in for everything to work again.

Please advise on how to handle this. We want the app to always receive messages even when user locks device or at least some method to make the app function again when coming back online.

Also, when the user is using WI-FI and the WI-FI connection is interrupted we experience similar results. The user misses messages, etc…

I’ve read everything from services workers, push notifications, to keeping the device awake and more.

What is the best method to solve this issue? Thanks so much!

I’m thinking I’m may create an angular service to check the mobile device online status, and when the user comes back online, fetch the missed messages but I don’t know if this is the best practice.

Reading this Comet Chat article, I see there is an “Offline Messaging Queuing” feature.

How does this work? Is this functionality available in the CometChat Pro API/SDK?

Any suggestions would be greatly appreciated. Thanks!

Hello @kl2000,

Can you please let us know which SDK & the version of the SDK are you using?

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi Mayur,

@cometchat-pro/cordova-ionic-chat":

  "version": "2.0.11"

Thanks!
Kyle

Hello @kl2000,

Thank you for the information. I will get this check on our end and get back to you with an update.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hello @kl2000,

Can you also provide us with the iOS version of the device as well?

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi @mayur.bhandari the last IOS device we tested on was latest version 13.7 but we experience the same issue on Android as well. Thanks!

Hello @kl2000,

I did test a few scenarios on Android (OS 8.1.0)

  1. I locked the phone keeping the app in the foreground state. After 5 mins I unlocked the phone and was able to receive real-time messages.

  2. I locked the phone keeping the app in the background state. After 5 mins I unlocked the phone and was able to receive real-time messages.

To test the reconnection:

  1. I turned off the WiFi(the mobile network was not on at any time) and locked the phone keeping the app in the foreground state. After 5 mins I unlocked the phone and was able to receive real-time messages.

  2. I turned off the WiFi(the mobile network was not on at any time) and locked the phone keeping the app in the background state. After 5 mins I unlocked the phone and was able to receive real-time messages.

I would advise you to use the Connection Listeners which will give you a real-time update of the Connection. Please check the documentation for Connection Listener here.

Warm Regards,

CometChat Pro
Mayur Bhandari

HI Mayur thanks. I totally looked over the Connection Listeners.

Question, is there a way to get the last delivered message ID for a particular group?

CometChat.getLastDeliveredMessageId().then(msgId => {
latestId = msgId;
});

Hello @kl2000,

Can you please let us know what are you trying to achieve to help us understand. So that we can provide a better way to achieve it.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi @mayur.bhandari, on the main landing page of our app, we load in messages from a public group.

Users can click on any of the messages and start a conversation.

I’ve tested out the connection listeners you recommended and they work great. Now we would like to load any messages the user may have missed from our main landing page group when the user goes offline for an extended period.

The getLastDeliveredMessageId() function works, but it loads in the ID for the last sent message for all groups. At least it appears that way.

So, we were hoping we could capture the last message ID for our main group, then pass it to the MessagesRequestBuilder and fetch the next (missed) messages.

We could probably record the last message ID and store it in Firebase but we were looking for an easier solution.

Thanks so much for your help and time.
Kyle