如何将动作按钮添加到离子推送通知?
答
的操作按钮应在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}
]
}
}
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#action-buttons
答
在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();
});
+0
这是一个解决方案,如果我有我的应用程序在后台运行,或者如果它是opened.If我的应用程序停止通知悄无任何button.I've发现但是仍然不能正常工作... – ggigle
我试过了......仍然没有工作... 这是我的json: { \t“tokens”:[ “令牌”], \t “轮廓”: “crewapp”, \t “通知”:{ \t \t “消息”: “阿罗哈”, \t \t “动作”:[ { “图标”: “emailGuests”, “标题”: “EMAIL GUESTS”,“callback”:“app.emailGuests”,“foreground”:true}, {“icon”:“snooze”,“title”:“SNOOZE”,“callback”:“app.snooze”, “foreground”:false} ] \t} \t } 我正在使用cordovaV5 push plugin.Should be a reason? – ggigle
什么意思是“不工作”?是否收到通知?也许按钮不显示?显示,但回调失败? –
通知成功收到。但没有任何按钮被添加到通知 – ggigle