使用 Ionic 推送通知显示操作

Show actions with Ionic push notifications

我正在尝试使用 Ionic custom push notifications and the phonegap-plugin-push.

实施通知操作

不幸的是,即使消息和标题工作得很好,我也没有运气显示操作按钮。

这是我的 cURL 请求:

curl -X POST -H "Authorization: Bearer XXXXXXXXXXXXXXX" -H "Content-Type: application/json" -d '{
"tokens": ["XXXXXXXXXXXXXXX"],
"profile": "push01",
"notification": {
    "message": "test",
    "android": {
      "title": "test android",
      "data": {
        "actions": [
          { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": true},
          { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false }
        ]
      }
    }
  }
}' "https://api.ionic.io/push/notifications"

知道我做错了什么吗?

谢谢!

显然某些 SDK 库版本存在某种不兼容问题。

参考:https://github.com/phonegap/phonegap-plugin-push/issues/767

回调函数 "app.emailGuests" 需要可以从全局范围访问。

像这样:

window.app = {};
window.app.emailGuests = function(data){
    // Do stuff when button is clicked
    console.log('Notification data: ', data);
};