react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

onNotification not working on iOS

Open witalobenicio opened this issue 8 years ago • 4 comments

I'm trying to send a push notification to iOS, but the method onNotification just didn't get called. I already configured PushNotificationIOS according to RN Docs, I enabled Push Notifications in developer account and in my project capabilites. That is my code to configure in JS:

PushNotification.configure({

  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function(token) {
    Auth.saveNotificationToken(token.token);
    console.log( 'TOKEN:', token );
  },

  // (required) Called when a remote or local notification is opened or received
  onNotification: function(notification) {
    console.log( 'NOTIFICATION:', notification );

    // process the notification

    // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
  senderID: "87065697363",

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   */
  'content-available': 1,
  requestPermissions: true,
});

witalobenicio avatar Feb 21 '18 17:02 witalobenicio

Why did you close this? What did you resolve? I'm dealing with this same issue on iOS. No notifications received, looks just like yours.

tmaly1980 avatar Mar 15 '18 18:03 tmaly1980

Not sure why this issue would be closed without even addressing / commenting on it. From my experience, this is a valid issue on iOS 11. It seems like PushNotificationIOS is not updated to support iOS 11 (FYI - iOS 11 has a newer delegate method that you need to implement to get this working).

Custom coding maybe needed on AppDelegate since UILocalNotification object has been deprecated since iOS 11

pathikb avatar Apr 03 '18 07:04 pathikb

React Native Push Notifications clearly states that we need to call configure outside of the React Native Lifecycle. This is very important.

https://product.farewell.io/visible-react-native-push-notifications-that-work-on-both-ios-and-android-5e90badb4a0f

https://prnt.sc/k61hz7

iamrutvik avatar Jul 13 '18 12:07 iamrutvik

Still facing same issue. Does anyone have solution for this? I am using iPhone XS Max.

Aayushi1301 avatar Oct 07 '20 16:10 Aayushi1301