Firebase Invalid Registration on iOS

Hello,

I am using the capacitor push notifications along with firebase.
Android works perfectly, but iOS never get the messages.

Using firebase console, i can send a push for both platforms and they get it.
But using the device token, it works for android but it complains about iOS token, InvalidRegistration.

The android token looks like this:
cRpVf5fS4WI:APA91bGcb_MspvHFTvkuFNoST9oNatvVG8Q95RvoL8ZmQ7n8-tjAJYhTA4kaGoW-RjXuZtfHgcWj4e_L2_rd5rNLFOYjwrLBEw9zErQtmIM0R1hr1XCGXMqE11iMmFgQqef9Uoe_dVBx

and the iOS looks token like this:
C65B91B67913CBD803E347Es27FDE7vA6D5B5C43738390DAD2B68FF47C80F8F8

They look quite different, so i imagine iOS one may be wrong…

The code:

if (this.platform.is(“mobile”) && this.platform.is(“hybrid”)) {

  PushNotifications.addListener(
    "registration",
    (token: PushNotificationToken) => {
      
      console.log(token);
      
    }
  );

}

I have the same problem.
Have you been able to find the solution?

Hi,

Yes, i solved the problem. I dont know if the problem persists nowadays, but at the time, this is what i did:

If the token has a “:”, then it returned an APNS token instead of a FCM Token. In this case, I call an API from google to convert it to FCM Token.

   return this.http.post(
      'https://cors-anywhere.herokuapp.com/https://iid.googleapis.com/iid/v1:batchImport',
      {
        application: 'com.your.app',
        sandbox: false,
        apns_tokens: [apnsToken],
      },
      {
        headers: new HttpHeaders({
          'Content-Type': 'application/json',
          Authorization:
            'key=XXXXXXXXXXXXXXX',
        }),
      }
    );

Remember that, for using Push Notifications in iOS, you need to configure the apple certificates.

Actually, they have solved it. Take a look at the DOCs

https://capacitorjs.com/docs/guides/push-notifications-firebase#add-initialization-code

1 Like