wix / react-native-notifications

React Native Notifications
MIT License
3.23k stars 763 forks source link

postLocalNotification does nothing, no notification shown #986

Open nbobic1 opened 1 year ago

nbobic1 commented 1 year ago

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?

RaghavStepron commented 1 year ago

Share code please

nitrique commented 1 year ago

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
Vpvladimirov commented 1 year ago

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?

SirCameron commented 1 year ago

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

nitrique commented 1 year ago

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

Vpvladimirov commented 1 year ago

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.

SirCameron commented 1 year ago

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.

Vpvladimirov commented 1 year ago

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.

SirCameron commented 1 year ago

@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.

chenweigh commented 1 year ago

same problem + 1

chenweigh commented 1 year ago

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 commented 1 year ago

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
tremblerz commented 12 months ago

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