Firebase Push Notification not fire listener on IOS

I integrated Firebase Push Notification in my ionic capacitor app.

It works on Android but on iOS registration listener not fired after permission granted. I can’t understand why.

PushNotifications.addListener('registration', (token: Token) => {
      alert('Push registration success, token: ' + token.value);
      this.push.registerToken(token.value);
    });

    PushNotifications.addListener('registrationError', (error: any) => {
      alert('Error on registration: ' + JSON.stringify(error));
    });

    PushNotifications.addListener(
      'pushNotificationReceived',
      (notification: PushNotificationSchema) => {
        alert('Push received: ' + JSON.stringify(notification));
      },
    );

    PushNotifications.addListener(
      'pushNotificationActionPerformed',
      (notification: ActionPerformed) => {
        alert('Push action performed: ' + JSON.stringify(notification));
      },
    );

    PushNotifications.requestPermissions().then(result => {
      if (result.receive === 'granted') {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register().then((response) => {
          alert("registration complete");
          console.log('[NOTIFICATIONS] register complete: ', response);
        }, (err) => {
          alert("registration error");
          console.error('[NOTIFICATIONS] register error: ', err);
        });
      } else {
        // Show some error
      }
    });

alert(“registration complete”); is called but after nothing

Could you please help me to understand?

Did you enable the push capability in Xcode?

Are you following this guide or using some other plugin?

Did you add all the code specified in Push Notifications - Firebase | Capacitor Documentation?

1 Like

Thanks @julio-ionic. I followed all the instructions but I didn’t change the native code (the swift file). It is necessary?

yes, it is, that’s what get Apple’s response on successfully getting the token or if there was a failure on getting the token, if you don’t add that, then the javascript side won’t get any response