5

Socket.io channel disconnects whenever the app is in background or closed, how to keep channel connected all time because i have to include push notification feature to my chat application.

1 Answer 1

9

What is the best way to handle notifications on react-native

It depends on the platform that you support, to receive mobile push notification on the device the best way is to implement the platform specific solution.

Why do you do that ?

Because even if you app is close or in background, the user will get notification on the screen and you can handle it

For iOS:

You have use an APNs server to send push notification

For Android:

You have to use GCM

To make the implementation of that even easier you can use services like:

How to implement that with react-native ?

You have really good libraries to do that:

With react-native-push-notification

here is an example with this library:

var PushNotification = require('react-native-push-notification');

PushNotification.configure({
    onRegister: function(token) {
        // Call when your device register the token
        // You have to pass this token to the API or services like OneSignal, Pusher etc...
        console.log( 'TOKEN:', token );
    },

    // This is trigger when a remote notification is received or open
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );
    },

    // This is only for Android
    senderID: "YOUR GCM (OR FCM) SENDER ID",

    // This is only for iOS
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },

    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,

    // Ask the permission to receive notifications
    requestPermissions: true,
});

You also have libraries that implement the service of your choice like :

I hope my answer help you 😊

Sign up to request clarification or add additional context in comments.

1 Comment

@JulienKode can you please tell me how to fire some action when user tap on notification ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.