@lado wrote:
Hello,
I have two questions for one goal
I’m trying to figure out, how to show and increase Push Notification from my Google Firebase with badge counter of Ionic2 application in background with Android device.
For example, function below lets to increment or decrements Notification Badge Counter with button click in home.html form home.ts just as example:
async increaseBadges(badgeNumber: string) { try { let badge = await this.badge.increase(Number(badgeNumber)); console.log(badge); } catch (e) { console.log(e); } }
Code in app.component.ts popups Push Notification from Google Firebase with opened app, but I can’t figure out, how properly show and increment Badge Counter with Push Notifications with app icon in background.
And also with press on “View” now I got nothing, as I’m not sure, how to get notification itself with click to “View” on popup to open message text and at the same time decrease Badge Counter.
Advice would be helpful:
initPushNotification() { this.push.hasPermission() .then((res: any) => { if (res.isEnabled) { console.log('We have permission to send push notifications'); } else { console.log('We don\'t have permission to send push notifications'); } }); const options: PushOptions = { android: { senderID: 'My sender ID' }, ios: { alert: 'true', badge: true, sound: 'false' }, windows: {} }; const pushObject: PushObject = this.push.init(options); pushObject.on('notification').subscribe((notification: any) => { console.log('Received a notification', notification); let confirmAlert = this.alertCtrl.create({ title: 'New Notification', message: JSON.stringify(notification), buttons: [{ text: 'Ignore', role: 'cancel' }, { text: 'View', handler: () => { // TODO: Your logic here // self.nav.push(DetailsPage, {message: data.message}); } }] }); confirmAlert.present(); }); pushObject.on('registration'). subscribe((registration: any) => console.log('Device registered', registration)); pushObject.on('error'). subscribe(error => console.error('Error with Push plugin', error)); }
Posts: 1
Participants: 1