Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add action buttons to ionic push notifications?

I want to add some action buttons to ionic push notification. I'm using cordova pushv5. The notifications works fine but I don't know how to add these buttons.

How do I add these buttons?

like image 843
ggigle Avatar asked Oct 27 '25 23:10

ggigle


2 Answers

The Action Buttons should be added at the POST request.

{
"registration_ids": ["my device id"],
"data": {
    "title": "AUX Scrum",
    "message": "Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.",
    "actions": [
        { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": true},
        { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false}
    ]
   }
}

enter image description here

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#action-buttons

like image 53
Pablo Albaladejo Avatar answered Oct 29 '25 13:10

Pablo Albaladejo


In PushV5's notificationReceived event, you could pop up the notification with Ionic's Alert Component, which has customizable buttons.

$rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){
   let alert = alertCtrl.create({
      title: data.title,
      message: data.message,
      buttons: [
      {
          text: 'Nope',
          handler: data => {
            console.log('Nope clicked');
          }
      },
      {
          text: 'OK',
          handler: data => {
            console.log('OK clicked');
          }
      }
    ]
   });

   //popup the alert
   alert.present();
});

https://ionicframework.com/docs/components/#alert

like image 30
Cody Parker Avatar answered Oct 29 '25 15:10

Cody Parker