Dear Backendless Support Team,
I’m using Backendless iOS SDK to implement the real-time messaging function in my app. I noticed there is something wrong with message listener when user presses the home button and moves the app to the background. Hope you could take a look. Detailed information are as follows.
In RTClient.swift, in the subscribe method, there is
self._lock.lock() action. The condition of unlock is either
self.socketConnected or execute
self.connectSocket and unlock in the connected handler. Notice the
self.connectSocket is an async method and usually it’ll take time.
However, when user press home button and the app goes to background, there is a chance that the connection is lost. Therefore the
self.needResubscribe will be set to true. App will call subscribe once and onConnectionHandlers will call subscribe again because
self.needResubscribe is true. Thus the deadlock.
Backendless Version (3.x / 5.x, Online / Managed / Pro )
Client SDK (REST / Android / Objective-C / Swift / JS )
- I start a message listener in my ‘ChatRoom’ view controller. Then I press the home button and the app goes to background. After a while when I re-enter the app, the listener should work, or at least I can add a new listener to make the
- After re-entering the app, the listener won’t receive new messages anymore. I didn’t close the app for the entire process.
- I can’t add new listener either. When I call addCustomObjectMessageListener, nothing happened. No error code, response handled isn’t called, error handler isn’t called.
- I tried removing all listeners before the app goes to background and add listener when app reopens, still not work.
- This not just happens to MessageListener, also happens to realtime database listener.
Reproducible Test Case
Real time chat sample code provided in the
code generation section is a good example. It has the same problem. When the app goes to background and re-enters into foreground, the chat is dead. Publish still works but the message listener is dead.