ami*_*ito 7 firebase react-native firebase-cloud-messaging react-native-push-notification
我正在使用react-native-push-notification并遵循其文档。当应用程序位于前台时,它工作正常,但是当应用程序位于后台时,我尝试从Firebase控制台发送通知,只是在状态栏中显示了该应用程序的一个小图标,但未显示横幅
我试图添加一个新频道,但仍然无法正常工作

componentDidMount() {
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log( 'TOKEN:', token );
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
Platform.OS === 'ios' ? notification.finish(PushNotificationIOS.FetchResult.NoData) : null;
},
// ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: Variables.GCM_SENDER_ID,
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
visibility: 'public',
popInitialNotification: true,
requestPermissions: true,
});
}
Run Code Online (Sandbox Code Playgroud)
您必须创建一个 android 通知通道并设置您希望它具有的配置,例如,
{
channelId: "general-or-something",
channelName: "General or Something",
channelDescription: "Description for general or something",
playSound: true,
importance: "High",
vibrate: true,
}
Run Code Online (Sandbox Code Playgroud)
既然你已经安装了react-native-push-notification,你可以使用该方法PushNotification.createChannel()来创建频道,它看起来像这样,
PushNotification.createChannel(
{
channelId: Channels.GENERAL.channelId,
channelName: Channels.GENERAL.channelName,
channelDescription: Channels.GENERAL.channelDescription,
playSound: true,
importance: Importance.HIGH,
vibrate: true,
},
() => null,
);
Run Code Online (Sandbox Code Playgroud)
并在您的firebase.json文件中添加一个新的道具,messaging_android_notification_channel_id将 Channels.GENERAL.channelId 分配给它,这将帮助您覆盖 firebase 创建的默认频道,并让您在其之上使用您的配置。
| 归档时间: |
|
| 查看次数: |
473 次 |
| 最近记录: |