Ad

PushNotificationIOS.presentLocalNotification() Doesn't Work In React-native

- 1 answer

I'm trying to use PushNotificationIOS in react-native, but nothing happens.

I have the following code:

PushNotificationIOS.requestPermissions();

PushNotificationIOS.presentLocalNotification(
  {
    alertBody: 'Hello world!!!'
  }
);

I'm running on a device and I did enable notifications for my app.

Moreover, when I run

PushNotificationIOS.checkPermissions((permissions) => {
  console.log(permissions);
});

It returns me

{ badge: 1, sound: 1, alert: 1 }

Indicating that the notifications have indeed been enabled.

However, I still cannot see anything on the screen.

Ad

Answer

Solved! I was trying to display a push notifications while still having the app in the foreground. Of course, that wouldn't work. An app has to be in the background for a push notification to work.

Ad
source: stackoverflow.com
Ad