Push notification 离子4、Firebase-x和FCM按钮通知,带有操作按钮
我正在尝试使用firebase-X本机插件处理推送通知,将操作按钮添加到通过firebase admin SDK发送到我的Ionic 4应用程序的推送通知中。我的应用程序运行在android和ios上 以下是我当前成功向我发送推送通知的脚本:Push notification 离子4、Firebase-x和FCM按钮通知,带有操作按钮,push-notification,firebase-cloud-messaging,ionic4,action-button,Push Notification,Firebase Cloud Messaging,Ionic4,Action Button,我正在尝试使用firebase-X本机插件处理推送通知,将操作按钮添加到通过firebase admin SDK发送到我的Ionic 4应用程序的推送通知中。我的应用程序运行在android和ios上 以下是我当前成功向我发送推送通知的脚本: exports.sendDebugPush = functions.pubsub.schedule('* * * * *').onRun((context) => { let promises: Promise<any>[] =
exports.sendDebugPush = functions.pubsub.schedule('* * * * *').onRun((context) => {
let promises: Promise<any>[] = [];
return admin.database().ref('/users/******').once("value")
.then( user => {
let todos = [];
for(let key in user.val().nextActions) {
if(user.val().nextActions[key].active != false) {
let todo = user.val().nextActions[key]
todo['todoid'] = key;
todos.push(todo);
}
}
if(todos.length > 0) {
//currently we pick a random todo, later on the one with the highest priority
//todos.sort((a, b) => (a.priority/1 < b.priority/1) ? 1 : -1);
let randomTodo = todos[Math.floor(Math.random()*todos.length)]
let payload: any = {
notification: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString()
},
data: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString(),
target: 'todo',
todoid: randomTodo.todoid
}
};
Object.values(user.val().devices).forEach( (device) => {
promises.push(admin.messaging().sendToDevice(String(device), payload));
});
}
return Promise.all(promises)
.then( () => {
console.log('success!');
})
.catch( error => {
console.log('failed :(');
console.log(error);
});
});
});
它也成功地做到了这一点。我成功地处理了点击推送通知,这样它就可以重定向到我的待办事项页面,以获得这种推送通知(带有“target”属性的推送通知)。但现在我想在推送通知中添加两个操作按钮“开始”和“跳过”,以开始或跳过相应的待办事项。说清楚一点,我说的是后台推送通知,所以应用程序没有打开。然后,用户会在手机上收到一个标准的推送通知,我希望有两个动作按钮可以在不打开应用程序的情况下执行一个动作
我尝试了各种各样的有效载荷,第一次甚至显示我的行动按钮,但并没有实现。例如,以下内容不适用于我:
let payload: any = {
notification: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString()
},
data: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString(),
target: 'todo',
todoid: randomTodo.todoid,
"actions": [
{ "icon": "approve_icon", "title": "APPROVE", "callback": "AppComponent.approve", "foreground": true},
{ "icon": "reject_icon", "title": "REJECT", "callback": "AppComponent.reject", "foreground": true}
]
}
};
事先非常感谢您的帮助,如果还有什么不清楚的地方,请告诉我。:)
let payload: any = {
notification: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString()
},
data: {
title: "Gossik",
body: "Hoiiiii " + new Date().toISOString(),
target: 'todo',
todoid: randomTodo.todoid,
"actions": [
{ "icon": "approve_icon", "title": "APPROVE", "callback": "AppComponent.approve", "foreground": true},
{ "icon": "reject_icon", "title": "REJECT", "callback": "AppComponent.reject", "foreground": true}
]
}
};