I am making an application in React Native and a Google Firestore backend.
Using the Firestore API, I can set a listener on the contents of the chat so that the app can react instantly to new changes such as updating the screen or notifying the user. The problem is that this does not work when the phone's screen is locked, since then the listener is no longer active.
What does work, even when locked, is sending a push notification to the app. The problem is that due to Firestore limitations (Firestore's OnCreate method has a few second delay on being triggered), this is much slower and thus does not work to instantly receive messages when sent. This also means that I have to push a lot of notifications when users are simply chatting and that's exactly why the Firestore listener exists.
Do I really have to write some ugly listener/notification hybrid to deal with this, or is there something I'm not seeing?
Thanks!
The issue is not with Firestore. The issue is that the operating system is shutting down the app's network access in order to save battery and network costs. This is not something you have a whole lot of direct control over. The user's battery life is more important than the code running in anyone's app. This behavior is something you'll need to accept and work with.
The push notification works because you are signaling to the OS that it should wake up the app so it can do some more work. It will do that for a time, then shut the app down again to save battery and network.
You don't really have any alternatives to implement "instant" updates - the system you're describing is working as expected.