wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

In android events are not getting triggered in. #982

Open chaitanya71998 opened 1 year ago

chaitanya71998 commented 1 year ago

Hi

I was integrating react-native-notifications package to react native app. With ios it is working absolutely superb. But for android this not working completely. apart from registerRemoteNotificationsRegistered remaining events are not at all getting triggered.

//index.tsx
import {Notifications} from 'react-native-notifications'
...
  useEffect(() => {
    Notifications.registerRemoteNotifications()
    Notifications.events().registerRemoteNotificationsRegistered(
      (event: Registered) => {
        console.log('registerRemoteNotificationsRegistered', event)
      },
    )
    Notifications.events().registerNotificationReceivedForeground(
      (
        notification: Notification,
        completion: (response: NotificationCompletion) => void,
      ) => {
        console.log('registerNotificationReceivedForeground', notification)//not getting triggered
        // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
        completion({ alert: '1', sound: '1', badge: '0' })
      },
    )

    Notifications.getInitialNotification()
      .then(notification => {
       console.log(notification) // getting undefined, everytime
      })
      .catch(err => {
      })

    Notifications.events().registerNotificationOpened(
      (
        notification: Notification,
        completion: () => void,
        action: NotificationActionResponse,
      ) => {
        console.log(notification) //not getting triggered
        completion()
      },
    )

    Notifications.events().registerNotificationReceivedBackground(
      (
        notification: Notification,
        completion: (response: NotificationCompletion) => void,
      ) => {
        console.log('registerNotificationReceivedBackground', notification) ////not getting triggered
        completion({ alert: true, sound: true, badge: false })
      },
    )

    webengage.push.onClick(function (notificationData: { [x: string]: any }) {
console.log(notificationData) // working fine
    })
  }, [])

I have followed the steps in the installation docs as it : https://wix.github.io/react-native-notifications/docs/installation-android version: "react-native-notifications": "^4.3.5",

stale[bot] commented 1 year ago

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

disrae commented 1 year ago

I'm also having this issue. I don't know if some code somewhere is causing issues with the library, but aside from the events having been triggered a few times in the past, I can't get them to trigger again, I guess we are the minority? We have probably done something to interfere with the library 🤔

luca-tomasetti commented 11 months ago

I'm experiencing something similar with version 5.1.0 when I'm trying to handle the notifications in the foreground for Android. For iOS seems fine and the event is triggered

Barney4242 commented 8 months ago

I don't know if this problem exists for you or not, but I added android.permission.SYSTEM_ALERT_WINDOW and it's gone.