I'm currently facing an issue with push notifications in an iOS React Native app. While I have made progress in getting it to work, there is one obstacle I cannot overcome. The problem lies in the fact that my code for displaying a notification when the app is running in the background doesn't actually execute until the app becomes active again. I am using Socket.io to listen for events, such as onChat, but the corresponding code isn't triggered until the app is brought back into focus. Despite ensuring that the socket connection remains established.
An interesting observation is that the feature works flawlessly in the simulator but fails to do so on my actual device. This discrepancy has led me to believe that there may be performance optimizations at play which pause JavaScript execution when the app is minimized.
How can I go about allowing my JavaScript code to run even when the app state is in the background?
The current approach involves calling a function upon receiving an event over the socket:
PushNotificationIOS.presentLocalNotification({
alertBody: `New Chat: ${chat.message}`,
});