react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
753 stars 288 forks source link

"register" and "registerError" events don't fire on React Native@0.70.6 React@18.1.0 #400

Open alexandergx opened 1 year ago

alexandergx commented 1 year ago

The "register" and "registerError" events don't seem to fire on React Native version 0.70.6. I just tried a fresh project init, and still no success.

package.json:

"react": "18.1.0", "react-native": "0.70.6"

AppDelegate.h and AppDelegate.mm have been configured properly. Xcode Background Mode > Remote Notifications and Push Notifications have been set properly. App builds and runs fine. But the two listener events do not ever fire.

Is this known? Are there any solutions?

atifgulzar commented 1 year ago

I have the same issue

PushNotificationIOS.requestPermissions().then(data => { PushNotificationIOS.addEventListener('register', token => { alert(token); }); });

ErkanGorgulu commented 2 weeks ago

In this library, I have found that you have to call PushNotificationIOS.addEventListener('register' before PushNotificationIOS.requestPermissions so register is triggered after the user presses allow. Also if you want to get the device token on every reload, you could call a silent local notification to trigger the register event. Like so;

PushNotificationIOS.addNotificationRequest({
        id: 'default',
        title: '',
        body: '',
        isSilent: true,
      });