Push notifications not working

Please provide the following:

  1. SDK Version: 39
  2. Platforms: iOS/Android

I have an ejected app where we use push notifications.
Notifications are working as expected for both Expo client and TestFlight build, but the production app doesn’t handle notifications correctly, seems like the handler function is not executed.

This is the code we have:

class RootStack extends Component {
  async componentDidMount () {
    // Listener for notifications opened while the app is on background.
    this.notificationOpenedListener = 
    Notifications.addNotificationResponseReceivedListener(this.onNotificationOpened)
    // Listener for notifications received while the app is running - foregrounded.
    this.notificationReceivedOnForegroundListener = Notifications.setNotificationHandler({
      handleNotification: this.onNotificationReceivedOnForeground,
      handleError: error => {
        const cleanError = cleanseErrorForLogging(error)
        Logger.error('Error while handling notification - app was in foreground', cleanError)
      }
    })
    this.createAndroidPushChannel()
  }

  onNotificationOpened = ({ notification }) => {
    // Do some stuff with the notification
  }

  onNotificationReceivedOnForeground = async (notification) => {
    // Do some stuff with the notification
  }
}

I can’t figure out what is missing here, does anyone had this issue before?

Hey @brightplan, am I correct in assuming that the notifications are delivered properly (at the OS level)? Also, I see you listed Android under the affected platforms…is the same thing happening (well, more accurately not happening) on both?

Cheers,
Adam

Hi @brightplan. I don’t speak english very well, but I will try to help u with my little experience…

At last I used import Notifications about expo, but now existing expo-notifications, that can u install e import into your project… look at this lines in my code, how was and witch I’m using now:

// import { Notifications } from ‘expo’; DEPRECTATED
import * as Notifications from ‘expo-notifications’;

If u’re using like first line, you can take a problem with notifications, but the second line is the correct use. So, if u using Notifications from expo, install expo-notifications and imports Notifications from expo-notifications. Bro, this change solved my problems with notifications!

Sorry about my english… rsrsrs

Regards

Hi guys, thank you both for your replies.

@adamjnav
Both OS receive every notification, the problem is when each notification is handled. We added some logs to see how each handler behaves in prod, but our concern is why we have a difference between Expo client - TestFlght and the prod app.

@edmardelima
I understood you perfectly :slight_smile: We use the second import you mentioned, we migrated Notifications API when it was modified (Expo SDK 38) and it has been working well since that moment.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.