Available options to fetch data from a server while on background in react-native

373 views Asked by At

I want to make an app with react-native (that will probably be running on an android phone) that will fetch messages from a server and will send them as SMS to a contact. The thing is that it needs to keep watching for new messages from the server, and that got me wondering how people deal with this kind of situation, specially when the app is running on background.

1 - Should I do something like setInterval on the background (with this) and keep fetching from the server to look for new messages, or is that too inefficient? If no, is there a specific case where I should use these background setInterval, or setTimeout or something similar?

2 - Should I use something like OneSignal with push notifications to handle this? When should I do that?

3 - I am using rails as back-end in another project, and rails 5 added ActionCable which enables using WebSockets. Is it possible to implement good and efficient notification feature for mobile apps using WebSockets instead of using OneSignal?

4 - Any other tips on notifications, running code on background, when to do something, when not do something, etc?

2

There are 2 answers

0
tennist On

You should use GCM(Google Cloud Messageing)to receive messages from the server, not otherwise. On iOS, use APNS.

0
Shailesh Prajapati On

You should use FCM(Firebase Cloud Messageing)to receive messages from the server. GCM is no longer maintain by google.use use this package to this functionality