Closed mrahmadt closed 5 years ago
Sharing my code as an example for anyone interested to use this plugin (please install the plugin and follow the instruction in the README file before using below code).
app.component.ts
initializeApp() { this.platform.ready().then(() => { if (Capacitor.isPluginAvailable('SplashScreen')) { Plugins.SplashScreen.hide(); } if (Capacitor.isPluginAvailable('PushNotifications')) { PushNotifications.addListener('pushNotificationReceived', (notification: PushNotification) => { alert('pushNotificationReceived ' + notification.body); console.log('pushNotificationReceived ', notification.body); }); PushNotifications.addListener('pushNotificationActionPerformed', (notification: PushNotificationActionPerformed) => { alert('pushNotificationActionPerformed ' + JSON.stringify(notification)); console.log('notification ', JSON.stringify(notification)); }); PushNotifications.addListener('registrationError', (error: any) => { alert('error on register ' + JSON.stringify(error)); console.log('error on register ', JSON.stringify(error)); }); } }); }
dashboard.page.ts
ngOnInit() { if (Capacitor.isPluginAvailable('PushNotifications')) { PushNotifications.register(); PushNotifications.addListener('registration', (token: PushNotificationToken) => { console.log('FCM ',token.value); }); } }
Thanks, that's it 😁 can you PR a freshed ionic app under an example folder?
Added a demo app
https://github.com/stewwan/capacitor-fcm-demo
Sharing my code as an example for anyone interested to use this plugin (please install the plugin and follow the instruction in the README file before using below code).
app.component.ts
dashboard.page.ts