Reputation: 1
FirebaseMessaging.addListener('notificationReceived', async (event: NotificationReceivedEvent) => {
console.log('Received foreground notification:', event);
await this.presentAlert(event.notification.body || '', event.notification.title || 'Notification');
await this.showLocalNotification({
title: event.notification.title || '',
body: event.notification.body || '',
data: event.notification.data
});
});
These are presentAlert and showLocalNotification
private async showLocalNotification(notification: {
title: string;
body: string;
data?: any;
}) {
try {
await LocalNotifications.schedule({
notifications: [{
title: notification.title,
body: notification.body,
id: Math.floor(Math.random() \* 100),
extra: notification.data,
sound: 'default',
smallIcon: 'icon',
largeIcon: 'icon',
iconColor: '#58B941'
}]
});
} catch (error) {
console.error('Error showing notification:', error);
}
}
async presentAlert(message: string, header?: string) {
const alert = await this.alertController.create({
header,
message,
buttons: [{
text: 'OK',
cssClass: 'alert-button-green', handler: () => console.log('OK clicked')
}],
cssClass: 'custom-alert'
});
await alert.present();
return alert;
}
I am trying to get alerts of same content as of notification, notifications getting trigerred but alerts or log statement are not getting executed in Ios or android.
Upvotes: 0
Views: 31