[英]Silent Notifications - Receive notifiaction in background without clicking on the notification
I use an ionic app with the plugin phonegap-plugin-push (v2.1.0) to receive push notifications on my Android an iOS device. 我将离子应用程序与插件phonegap-plugin-push(v2.1.0)一起使用,以在我的Android和iOS设备上接收推送通知。
So far it is working. 到目前为止,它正在工作。 When my app is in the background and I sent a notification, the notification will be sent to the device's system tray as a system notification.
当我的应用程序在后台并且发送通知时,该通知将作为系统通知发送到设备的系统托盘。 When I then click on the system notification it will appear inside my app
然后,当我单击系统通知时,它将显示在我的应用程序中
So in fact this event listener will be triggered: 因此,实际上将触发此事件侦听器:
this.pushObject.on('notification').subscribe(notification => {
....
});
But if I do not click on the system notification, but instead click on the app icon to open my app, the notification will not arrive inside my app. 但是,如果我不单击系统通知,而是单击应用程序图标以打开我的应用程序,则通知将不会到达我的应用程序内部。 So this event listener seems not to be triggered.
因此,似乎未触发此事件侦听器。
I found a possible solution which will use the finish-Method: 我找到了可能使用finish-Method的解决方案:
this.pushObject.on('notification').subscribe(notification => {
....
this.pushObject.finish(notification.additionalData.notId);
});
Also I should sent "content_available": '1' for Android and "content_available": 1 for iOS, as well as the notification id (notId) for iOS (only for iOS???) 另外,我应该为Android发送“ content_available”:'1',为iOS发送“ content_available”:1,以及为iOS发送通知ID(notId)(仅适用于iOS ???)
But nothing works. 但是什么都行不通。
Has someone a solution for that problem? 有没有人解决这个问题?
According to the plugin's Readme : 根据插件的自述文件 :
Note: if the push payload contained content-available: 1 then your notification event handler has already been called.
注意:如果推送负载包含content-available:1,则您的通知事件处理程序已经被调用。 It is up to you to handle the double event.
由您决定如何处理double事件。
Therefore, when you launch the app the event has already been called and you don't see it again when reopening the app. 因此,当您启动该应用程序时,该事件已被调用,并且在重新打开该应用程序时不会再次看到该事件。
I'm almost certain that by design, your push event's won't be triggered when opening the app from the icon instead of the notification itself. 我几乎可以肯定,根据设计,从图标而不是通知本身打开应用程序时,不会触发您的推送事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.