DEV Community

Discussion on: How to set up Firebase Push Notifications with Ionic & Vue.js

Collapse
 
jrgen_lundgren_7dd1bde5c profile image
Jörgen Lundgren

Thanks for the great post!
I had integrated Push Notifications with FCM for Ionic 4 Angular many times before, but really needed this informatino in order to do it for Ionic 5 Vue. But due to Capacitor 3 is now being used when you start a new ionic app, I had to do the following changes in order to play along with Capacitor 3:
The plugin capacitor-community/fcm does not support Capacitor 3 yet - read the issue here, so that can be skipped. Instead you have to use the native capacitor/push-notifications. Then you only import like this

import { PushNotifications } from '@capacitor/push-notifications';

No mods to MainActivity.java in Android Studio is needed then.
Also to fetch the fcm token, you obviously can't use this.fcm.getToken(), but you can to like this:

      PushNotifications.requestPermissions().then(result => {
        console.log('result ' + JSON.stringify(result));
        // Initialize the registration with FCM Token
        PushNotifications.register();
      });
      // On registration we can get the token
      PushNotifications.addListener('registration', (token) => {
        console.log('Push registration success, token: ' + token.value);
        //TODO: store token server side?
      });
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rizqisrijal profile image
rizqisrijal

Thank you sir for the update, can u help me with recent updates with capacitor and Vue. I've been looking anywhere but still can't figure it out. Can u make a brief tutorial sir. Thank you.

Collapse
 
marcoimproda90 profile image
Marco Improda

Ciao,
Thanks for your message and update! When I had written this post, I was still with Capacitor 2 and didn't know this issue. So it's great that you decided to share this update and solution :)