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

postLocalNotification does nothing, no notification shown

Open nbobic1 opened this issue 2 years ago • 13 comments

I tryed to implement this to show notification from my app, but it doesn't do anything. postLocalNotification returns id but doesn't show notification. I tryed running example, still no notifications showing. React Native implementation. Am I missing some part of implementation?

nbobic1 avatar Jul 26 '23 20:07 nbobic1

Share code please

RaghavStepron avatar Jul 28 '23 11:07 RaghavStepron

Hi,

Same here got the error on XCode : [native] JSON value '{ }' of type NSMutableDictionary cannot be converted to a date

With the example provided :

Notifications.postLocalNotification({ body: 'Local notification!', title: 'Local Notification Title', sound: 'chime.aiff', category: 'SOME_CATEGORY', fireDate: new Date(), })

Also types are wrong as shown:

Capture d’écran 2023-08-09 à 10 51 14

nitrique avatar Aug 09 '23 08:08 nitrique

Getting the same error for the wrong types - few of them does not exist (fireDate, category, etc) and some more are required. Anyone know what is happening? And if the fireDate is no longer present, how can you schedule a notification?

Vpvladimirov avatar Sep 01 '23 18:09 Vpvladimirov

Same issue here... types are wrong and method has no effect. Is this package maintained?

SirCameron avatar Sep 06 '23 13:09 SirCameron

Hi,

After couple of non working code with this library, I switched to @notifee/react-native

I use it to present firebase notification when app is open and in foreground, like Messenger do for example:

...
 // Resend notification for local display (RNFirebase don't do so)
    if (when === When.front && 'notification' in message) {
      // Create a channel (required for Android)
      const channelId = await notifee.createChannel({
        id: 'default',
        name: 'main channel',
      })

      // Display a notification
      await notifee.displayNotification({
        title: message.notification?.title,
        body: message.notification?.body,
        data: message.data,
        android: {
          channelId,
          localOnly: true,
          pressAction: {
            id: 'default',
          },
        },
      })
    }
...

Hope it helps, BR

nitrique avatar Sep 06 '23 14:09 nitrique

Hi,

After couple of non working code with this library, I switched to @notifee/react-native

I use it to present firebase notification when app is open and in foreground, like Messenger do for example:

...
 // Resend notification for local display (RNFirebase don't do so)
    if (when === When.front && 'notification' in message) {
      // Create a channel (required for Android)
      const channelId = await notifee.createChannel({
        id: 'default',
        name: 'main channel',
      })

      // Display a notification
      await notifee.displayNotification({
        title: message.notification?.title,
        body: message.notification?.body,
        data: message.data,
        android: {
          channelId,
          localOnly: true,
          pressAction: {
            id: 'default',
          },
        },
      })
    }
...

Hope it helps, BR

I switched to notifee as well. Very simple to setup, no native setup required, works like a charm.

Vpvladimirov avatar Sep 06 '23 20:09 Vpvladimirov

The issue with Notifee is that it doesn't fire an event when the app is in background and the notification is presented... I need to catch silent (data-only) notifications.

SirCameron avatar Sep 07 '23 10:09 SirCameron

The issue with Notifee is that it doesn't fire an event when the app is in background and the notification is presented... I need to catch silent (data-only) notifications.

What do you mean? It fires notifications when the app is in background, or even killed.

Vpvladimirov avatar Sep 07 '23 13:09 Vpvladimirov

@Vpvladimirov it doesn't fire an event when the notification is displayed, like it does for foreground notifications. I need this with silent notifications to run some background action.

SirCameron avatar Sep 08 '23 08:09 SirCameron

same problem + 1

chenweigh avatar Sep 18 '23 06:09 chenweigh

Here is how I solved it on iOS.

interface NotificationMessageType<T> {
  title: string
  body: string
  userInfo?: T
  sound?: string
  silent?: string
  category?: string
  fireDate?: string
}
const postLocalNotification = <T>(notification: NotificationMessageType<T>, notificationId?: number)=> {
    return Notifications.postLocalNotification(notification as unknown as Notification, notificationId)
}
postLocalNotification({ title: 'hello', body: 'world', fireDate: new Date().toISOString() })

chenweigh avatar Sep 19 '23 03:09 chenweigh

on Android, open notification happed wrong.

2023-09-19 16:44:50.670  1616-2770  ActivityTaskManager     system_server                        E  START {flg=0x10200000 hwFlg=0x10 cmp=com.chen.test/.MainActivity (has extras)} result: 3

chenweigh avatar Sep 19 '23 08:09 chenweigh

Switching to @notifee/react-native as well. Works flawlessly so far and their API appears to be more well-designed!

tremblerz avatar Oct 04 '23 14:10 tremblerz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jan 31 '25 23:01 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Feb 24 '25 23:02 stale[bot]