【问题标题】:Problems When Push Notification Sending to Another Device With react-native-firebase使用 react-native-firebase 将通知发送到另一台设备时出现问题
【发布时间】:2019-02-25 21:15:55
【问题描述】:

我很难使用 react-native-firebase 包向其他用户发送通知

环境详情:

  • react-native 0.58.4
  • react-native-firebase 5.2.2
  • Android 8

我没有使用 firebase 身份验证 - 身份验证由 API 完成。

react-native-firebase 文档(Android 通知)中描述的所有设置都已严格遵守。

流程:

用户已成功通过身份验证。然后你的频道就定义好了。

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');

这可行,如下图所示。

Notification Image

当我与另一个用户(在另一个设备上)进行身份验证并尝试发送相同的通知时,就会出现问题。它没有到达第一台设备。

是否需要通过 firebase fcm 进行身份验证?

或将通知显示到另一台设备的其他设置?

提前致谢。

【问题讨论】:

    标签: android firebase react-native firebase-cloud-messaging react-native-firebase


    【解决方案1】:

    你选择的方式,你只能发送本地通知。

    例如,如果您收到来自 FCM 的仅数据消息,则使用此方法,您的应用不会自动显示该消息...您必须处理此问题。 (描述为here

    要向其他设备发送通知,您必须使用firebase.messaging.RemoteMessage()

    看看这里:https://rnfirebase.io/docs/v5.x.x/messaging/upstream-messages

    希望对你有所帮助。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多