react-native-fcm icon indicating copy to clipboard operation
react-native-fcm copied to clipboard

Unable to show foreground notification in iOS 9.3.5

Open dslounge opened this issue 10 years ago • 2 comments

I'm testing notifications an ipod touch running iOS 9.3.5

"react-native": "0.33.0" "react-native-fcm": "2.3.0" Firebase/Messaging (3.7.1)

I'm having trouble presenting a notification when the app is in foreground. I've tried two different things and none of them work. I've tried:

  • Adding show_in_foreground to the notification payload.
  • Presenting a local notification when receiving the notification.

To be clear, my foregrounded app does see a silent notification, but I just can't show a banner.

I'm using a hybrid notification with notification and data. I need this notification to work for both iOS and Android:

{
  "to" : "fcmtoken",
  "notification" : {
    "title" : "Posted nearby: Story title",
    "body" : "location name",
    "icon" : "ic_stat_notify",
    "sound": "default",
    "click_action": "geosocial.story",
    "show_in_foreground": true //<---- added this but it doesn't do anything.
  },
  "data" : {
    "title" : "Posted nearby: Story title",
    "body" : "location name",
    "icon" : "ic_stat_notify",
    "story_id" : "10279"
  },
}

This is the code that handles the notification:

notificationUnsubscribe = FCM.on('notification', (notif) => {
    console.log('--received notification--');
    console.log(notif);
    const notifyStoryId = _.get(notif, 'story_id', null);
    if (notifyStoryId) {
      const title = _.get(notif, 'title', 'New Story!');
      const body = _.get(notif, 'body', 'A new story nearby!');

      const localNotif = {
        title,
        body,
        local_story_id: notifyStoryId,
        priority: 'high',
        // sound: 'default',
        icon: '@drawable/ic_stat_notify',
        large_icon: '@mipmap/ic_launcher_geosocial', //<-- for android
        show_in_foreground: true,
      };
      console.log('--trying local notification--')
      console.log(localNotif)
      //
      FCM.presentLocalNotification(localNotif);
    }
  });

When I send that message, the app actually receives it, as you can see by the console output:

image

However, FCM.presentLocalNotification( doesn't seem to do anything.

Is there anything I'm missing here? I seem to have this package and FCM hooked up correctly, I just can't get a foreground notification to fire. I'm wondering if I'm doing anything wrong. If I understand this documentation correctly, I shouldn't even have to try to fire a local notification in iOS, I should just be able to use show_in_foreground in the payload right?

dslounge avatar Oct 22 '16 04:10 dslounge

I am on Android 6.0 and while I receive the notification fine, FCM.presentLocalNotification({}) doesn't show any banner. Is it supposed to?

woniesong92 avatar Oct 30 '16 21:10 woniesong92

related to https://github.com/evollu/react-native-fcm/issues/218#issuecomment-266431726

sibelius avatar Dec 12 '16 13:12 sibelius