Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48981

@capacitor/push-notifications and FCM generate different tokens, crashes android

$
0
0

Ionic 5 app with Capacitor push notification and FCM plugins.

import { FCM } from '@capacitor-community/fcm';

import {
  ActionPerformed,
  PushNotificationSchema,
  PushNotifications,
  Token,
} from '@capacitor/push-notifications';

Why do they generate different tokens??

For Capacitor/PushNotifications, the following generates a token

PushNotifications.addListener('registration',
        async (token: Token) => {
          console.log('token: ' + token.value);
        }
      ).catch(e=>{alert('reqPerm'+e)});

While for FCM, the following generates a different token

FCM.getToken()
      .then(async (r) => {
         console.log(`token saved ${r.token}`)
        })
      .catch((err) => console.warn('error saving token', err));

The FCM token works on iOS (iPhone receives notifications), but registering it on Android, it says something about invalid token registered. So I had to use the token from PushNotifications.addListener for Android, but when it receives a notification, the app crashes.

I made sure that the google-services.json file is in the android/apps folder.

What gives?? Any suggestions?

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 48981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>