Push notification not showing in Android foreground

前端 未结 3 972
一生所求
一生所求 2021-01-05 11:36

I\'ve used react-native-fcm for remote notification in android and iPhone.

react-native-fcm

In Android foreground I\'m not be able to getting re

3条回答
  •  孤独总比滥情好
    2021-01-05 12:00

    As per the library issues listed here you can try two things:

    1. just pass show_in_foreground in your data property in remote notification

    2. android shows notification only when app state is killed or background. To display notifications in app foreground, you need to show local notification.

    Sample code:

    FCM.on(FCMEvent.Notification, notif => {
        if (!notif.opened_from_tray) {
            showLocalNotification();
        }
    });
    
    showLocalNotification() {
        FCM.presentLocalNotification({
          id: new Date().valueOf().toString(),         // (optional for instant notification)
          title: "Test Notification with action",      // as FCM payload
          body: "Force touch to reply",                // as FCM payload (required)
          show_in_foreground: true                     // notification when app is in foreground (local & remote)
        });
      }
    

    Full code is here

提交回复
热议问题