admin管理员组文章数量:1289508
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.
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.
Share Improve this question edited Nov 29, 2018 at 12:10 Julien Kode 5,4991 gold badge24 silver badges38 bronze badges asked Nov 29, 2018 at 11:51 Tejas Tejas 972 silver badges9 bronze badges1 Answer
Reset to default 9What 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:
- Urban Airship
- Amazon SNS
- Pusher
- OneSignal
- Firebase
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 :
- Pusher: react-native-pusher-push-notifications
- OneSignal: react-native-onesignal
- Firebase: react-native-firebase
I hope my answer help you
本文标签: javascriptHow to implement push notification with reactnativeStack Overflow
版权声明:本文标题:javascript - How to implement push notification with react-native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741407974a2377059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论