1

我正在探索离子应用程序中的Ionic 2插件。我添加了推送插件并将通知发送到我的应用程序。现在我的要求是点击通知操作按钮,以及如何在我的代码中链接回调。在这里我提到了我的通知JSON示例,以推动带有操作的通知按钮。Ionic 2推送通知操作按钮使用打字稿点击回叫

"data":{ 
"title":"Data title", 
"message":"Data message", 
"information": "Information", 
"actions": [ 
      { "icon": "approve_icon", "title": "APPROVE", "callback": "", "foreground": true}, 
      { "icon": "reject_icon", "title": "REJECT", "callback": "", "foreground": true} 
     ] 
} 

这里我将回调参数留为空。我如何将批准和拒绝方法链接到此回调参数中。请帮帮我。

回答

0

我正在查看文档,我假设this是您所指的插件。如果不是,那么链接相关插件的github页面会对您有所帮助。

阅读例子,似乎没有立即的帮助,但不要害怕,有人在离子论坛had the same issue。从实例有一个,看来你可以把你的函数的JSON像这样:

{ 
    "data": { 
    "title": "You have unread chats!", 
    "message": "Click here to read them.", 
    "actions": [ 
     { "title": "VIEW CHATS", "callback": "pushListener.callbacks.viewChats", "foreground": true}, 
     { "title": "SNOOZE", "callback": "pushListener.callbacks.snooze", "foreground": true} 
    ] 
    }, 
    "registration_ids":["foobar"] 
} 

本质上说,从我的理解,如果你把classname.functionname回调参数,那就是函数那会叫。

希望这会有所帮助!

+0

有效载荷我想是这样的。但我们的自定义事件批准不能被此方法接受。 ('approve',(e)=> {console.log(e); }); –

0

我已经达到了所需的解决方案。在启动器类中,通知操作按钮回调应该像这样。 (即)您必须将回调放入app.component.ts中。它的工作完美。

(<any>Window).approve = function (data: any) { 
    alert('Approve called); 
}; 

(<any>Window).reject = function (data: any) { 
    alert('Reject called); 
} 

//为Android

"data": { 
    "title": "Push notification", 
    "message": "Push notification with action button", 
    "actions": [ 
     { "icon": "approve_icon", "title": "Approve", "callback": "Window.approve", "foreground": true}, 
     { "icon": "reject_icon", "title": "Reject", "callback": "Window.reject", "foreground": true} 
    ] 
}