如何为离子推送通知添加操作按钮?

时间:2017-05-24 15:36:10

标签: cordova angular ionic-framework

我想在离子推送通知中添加一些操作按钮。我使用的是cordova pushv5。通知工作正常,但我不知道如何添加这些按钮。

如何添加这些按钮?

2 个答案:

答案 0 :(得分:4)

应在POST请求中添加操作按钮。

{
"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

答案 1 :(得分:0)

在PushV5的notificationReceived事件中,您可以使用Ionic的警报组件弹出通知,该组件具有可自定义的按钮。

$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