Meet Siraja
Meet Siraja

Reputation: 173

LocalNotification not working [IOS] - PushNotificationIOS

I'm trying to implementing local notification in IOS using this @react-native-community/push-notification-ios package.

I followed all the documentation properly. Still, LocalNotification is not working.

This is my environment config: - react-native : 0.61.4 - @react-native-community/push-notification-ios --save : 1.0.5

I did the following things,

  1. npm i @react-native-community/push-notification-ios --save
  2. cd ios && pod install
  3. Updated AppDelegate.m as per described here
  4. Made build : react-native run-ios --device "iPhone X"
  5. Then calling function in my js like this,
import PushNotificationIOS from "@react-native-community/push-notification-ios";
.
.
.
componentDidMount(){
  PushNotificationIOS.addEventListener('localNotification', this._onNotification);

  PushNotificationIOS.requestPermissions();
  PushNotificationIOS.presentLocalNotification({
    alertBody: 'Test Notification'
  });
}

_onNotification(notification) {
  console.log(notification._alert);
}
.
.
.

Upvotes: 0

Views: 4468

Answers (1)

Vizllx
Vizllx

Reputation: 9246

Well, when the app running in the foreground, you won't be able to see the notification. You can call the local schedule function and quick hide app to the background, then you will see the notification.

Source Code:-

PushNotificationIOS.localNotificationSchedule({
      message: "Local push notification",   //mandatory
      number: 1,
      date: new Date(Date.now() + (5 * 1000)) // Schedule in 5 secs
    });

Upvotes: 3

Related Questions