React-native-push-notification: iOS: onRegister only called with requestPermissions: true

Created on 18 Apr 2019  路  11Comments  路  Source: zo0r/react-native-push-notification

Hey,

I would like to run PushNotification.configure on app start _without_ immediately requesting permissions from the user, therefore I set requestPermissions to false. However, in this case onRegister never gets called. (Neither do I get an error via PushNotificationIOS.addEventListener). When I set requestPermissions to true, onRegister is called with the token correctly.

So... 1) is this by design? and 2) is there a way to get the token without requesting permissions?

(running on an iPhone XR -- real device -- with iOS 12.2; the push entitlement is set correctly in Xcode)

Most helpful comment

I can't seem to get onRegister to trigger at all.

All 11 comments

I can't seem to get onRegister to trigger at all.

Same. Triggered just fine on Android, but never called on iOS 10.x+. Works fine on iOS 9.x. 馃

I am running into this same issue. Has anyone found a cause, or better yet, a solution?

Have you enabled "Push Notifications" in Xcode - Capabilities for the application?

I'm having the same problem after updating from iOS 9 to iOS 11, react-native 0.57.1 to 0.61.2 and react-native-push-notification from 3.0.2 to 3.1.9

I enabled Push Notifications in Xcode - Capabilities for the application and also Remote Notifications on the Background Modes but it still doesn't fire the onRegister event, even after the user has Allowed notifications from the default prompt.
The push notification is also enabled in the Apple developer account, since this worked in a previous version that is already published on the app store.

Here is part of my code executed on the component:

componentDidMount() {
    PushNotification.configure({
      onRegister: token => {
        AsyncStorage.setItem('token', token.token);
      },
      onNotification: notification => {
        ...
      },
      senderID: 'XXXXXXXX',
      popInitialNotification: true,
      permissions: { alert: true, badge: true, sound: true },
      requestPermissions: true
    });
  }

Am I missing something after doing this updates?

This is happening for me as well, just nothing for onRegister.

I've tried putting it into state, asking later,

I've tried using my own Event delegator to get to it outside of the react scope

I've tried requestPermissions:true

Push notifications cert not expired

Push Notifications capability enabled in Xcode

Last time I updated the framework this happened as well, this part seems quite buggy...

Also, there's no error.. Since, the code is in Pods, is there a way to log what's happening? I see the code in the Pod, but I am not going to edit it...

Nevermind, I had forgotten to update the AppDelegate.m:

https://github.com/react-native-community/react-native-push-notification-ios

@atebit are you using RN version >0.60? If yes, why would you need to edit AppDelegate.m?

The problem seems to appear again: https://github.com/react-native-community/push-notification-ios/issues/106

@schumannd Even if you have RN version > 0.60, you still have to edit AppDelegate.m, auto-linking is going to edit it for you, it will just link project pods automatically. The changes reflected in AppDelegate.m forward notifications events to this module.

I have enabled push notifications and remote notifications. I have updated both .m and .h files as instructed (twice just incase). Changed the import format as well. Am I missing something here?
Screen Shot 2021-02-10 at 9 06 26 PM

Was this page helpful?
0 / 5 - 0 ratings