我很难使用react-native-firebase软件包向另一个用户发送通知
环境细节:
我没有使用firebase身份验证 - 身份验证由API完成。
react-native-firebase文档(Android Notifications)描述的所有设置都已严格遵循。
流:
用户已成功通过身份验证。然后定义您的频道。
fbase.messaging().hasPermission()
.then(enabled => {
if (!enabled) {
fbase.messaging().requestPermission();
}
});
const channel = new fbase.notifications.Android.Channel(userId, 'User Notifications', fbase.notifications.Android.Importance.Max)
.setDescription('Logged in users notifications');
//userId is 43
fbase.notifications().android.createChannel(channel);
然后如下向自己发送通知。
const notification = new fbase.notifications.Notification()
.setNotificationId('6878')
.setTitle(`Proposta respondida por Zé Carlos`)
.setBody('Sim, estamos à disposição. Chame-nos no chat qualquer coisa.')
.setData({
action: 'Proposta Respondida',
serviceOrderId: '68',
companyAvatar: null,
companyName: 'Auto Mecânica Joãozinho'
});
notification.android.setChannelId('43');
notification.android.setSmallIcon("ic_notification");
notification.android.setVibrate([1000, 1000]);
notification.android.setLargeIcon('imageUrl');
notification.android.setTicker('Não falou nada não falou em');
这有效,如下图所示。
当我与另一个用户(在另一台设备上)进行身份验证并尝试发送相同的通知时,会出现问题。它没有到达第一台设备。
它需要通过firebase fcm进行身份验证吗?
或其他设置,以显示通知给另一台设备?
先感谢您。
您选择的方式,您只能发送本地通知。
例如,如果您收到来自FCM的仅数据消息,而您的应用程序未自动显示该消息,则使用此方法...您必须处理此问题。 (描述here)
要将通知发送到其他设备,您必须使用firebase.messaging.RemoteMessage()
看看这里:https://rnfirebase.io/docs/v5.x.x/messaging/upstream-messages
希望,这对你有所帮助。