![](/img/trans.png)
[英]React-Native Handle push notification with react-navigation
[英]How to implement push notification with react-native
每当应用程序在后台或关闭时,Socket.io通道都会断开连接,如何始终保持通道连接,因为我必须在我的聊天应用程序中包含推送通知功能。
什么是处理react-native通知的最佳方法
取决于您所支持的平台,在设备上接收移动推送通知的最佳方法是实施特定于平台的解决方案。
你为什么要这么做?
因为即使您的应用关闭或在后台运行,用户也会在屏幕上收到通知,您可以进行处理
对于iOS:
您已使用APNs服务器发送推送通知
对于Android:
您必须使用GCM
为了使实现更加容易,您可以使用以下服务:
如何使用react-native实现呢?
您确实有很好的库可以做到这一点:
使用react-native-push-notification
这是该库的示例:
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,
});
您还拥有实现您选择的服务的库,例如:
希望我的回答对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.