React-native-push-notification: onNotification is not Called android When App is killed #1034

Created on 4 Apr 2019  ยท  5Comments  ยท  Source: zo0r/react-native-push-notification

Hi,

I have setup for the Local and remote notification in the App.js file, it's working fine in the iOS device also working fine android when App is not killed the onNotification is called.

But when App is killed in android at that time there is not called onNotification.

App.js

PushNotification.configure({
    // (optional) Called when Token is generated (iOS and Android)
    // smallIcon: "ic_notification",
    onRegister: function (token) {
      console.log('TOKEN:', token.token);
      setStoredData('deviceToken', token.token)
    },
    // (required) Called when a remote or local notification is opened or received
    onNotification: function (notification) {

      console.log('** NOTIFICATION: **', notification);

      if (Platform.OS === 'ios') {
        if (notification.alert.length !== 0) {
          handleNotification(notification)
          notification.finish(PushNotificationIOS.FetchResult.NoData);
        }
      } else {
        handleNotification(notification)
      }
    },
    senderID: "74898989898โ€,
    permissions: {
      alert: true,
      badge: true,
      sound: true
    },
    popInitialNotification: true,
    requestPermissions: true,
  });

And in the Home.js Called for notification.

PushNotification.localNotification({
      /* Android Only Properties */
      id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
      ticker: "My Notification Ticker", // (optional)
      autoCancel: true, // (optional) default: true
      largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
      smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
      bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
      subText: "This is a subText", // (optional) default: none
      color: "black", // (optional) default: system default
      vibrate: true, // (optional) default: true
      vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
      tag: 'some_tag', // (optional) add tag to message
      group: "group", // (optional) add group to message
      ongoing: false, // (optional) set whether this is an "ongoing" notification

      /* iOS and Android properties */
      title: "My Notification Title", // (optional)
      message: "My Notification Message", // (required)
      playSound: false, // (optional) default: true
      soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
      number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
      repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
      actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
    });

I Added local notification in Home.js so that is not called.

Can you please help me

Thanks.

Stale

All 5 comments

@kiritnim For me it worked when using - called after configuring PushNotification framework, when opening the app:

PushNotification.popInitialNotification((notification) => { Console.log(notification); })

@claudiumatei I face with a problem. When app is in foreground, it shows notification. When app is in background, no notification display. If I open app again, the notification show.
Do you face with this issue ?

@claudiumatei I face with a problem. When app is in foreground, it shows notification. When app is in background, no notification display. If I open app again, the notification show.
Do you face with this issue ?

Yes, Frustrating thing. no workaround here :( no one say's about this.

After many hours trying to fix this problem I think that I found the problem, When I change the build mode, from development to production the onMessage method works for all scenario (killed app, background and foreground) and both platforms.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssolida picture ssolida  ยท  3Comments

DanDance picture DanDance  ยท  3Comments

Kiran0791 picture Kiran0791  ยท  3Comments

nguyenvanphuc2203 picture nguyenvanphuc2203  ยท  3Comments

ahmadallo1 picture ahmadallo1  ยท  3Comments