android – React Native listen to Websocket to send Push Notifications?-ThrowExceptions

Exception or error:

I have an existing server that allows websocket connections, and publishes certain messages.

I’d like to start some kind of background task that can listen in on these messages and send a push notification to the user (even when the app is in the background).

What’s the best way to do this? I’ve found react-native-push-notification for sending local push notifications; but so far I haven’t really found anything that will let me keep a background process running. Looks like https://facebook.github.io/react-native/docs/headless-js-android.html might be promising.

How to solve:

So, after some research, I’ve realized this is just imply something you don’t do.

You instead have to have your app register with Google’s GCM Servers (in the case of android). You get back a token. You then send that token along to your server. When you want to push a notification, your server has to send that token along with the notification data to the GCM Servers.

Leave a Reply

Your email address will not be published. Required fields are marked *