简体   繁体   English

检测推送通知是否正在等待phonegap

[英]detect if push notification is waiting phonegap

I'm using the pushplugin with phonegap to send/ receive push notifications. 我正在使用带phonegap的pushplugin发送/接收推送通知。

I'm wondering if there is a way to detect this scenario (android and ios): 我想知道是否有一种方法可以检测到这种情况(android和ios):

  • push notification sent to phone 推送通知已发送到手机
  • user does NOT launch the app from the notification 用户未从通知中启动应用
  • time passes 时间流逝
  • user launches the app directly 用户直接启动应用
  • show an alert in the app to direct users to new content which was the purpose of the push notification, loading data from said push notification 在应用程序中显示警报,以将用户定向到推送通知的目的的新内容,并从该推送通知中加载数据
  • then, if possible, remove the push notification from the phones native notification tray/console 然后,如果可能,请从电话本机通知托盘/控制台中删除推送通知

I'm using the code to handle notifications as per the pushplugin guide, so for ios: 我正在使用代码按照pushplugin指南处理通知,因此对于ios:

to register device: 注册设备:

pushNotification.register(tokenHandler, errorHandler {
    "badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"
})

to handle a notification: 处理通知:

function onNotificationAPN(e) {
    if (e.alert) {
        // code here to show new content, works if user launches app through the notification
    }
}

similarly with android: 与android类似:

register device: 注册设备:

pushNotification.register(successHandler, errorHandler, {
    "senderID":"571716295846","ecb":"onNotificationGCM"
});

handle notification: 处理通知:

function onNotificationGCM(e) {
    if(e.payload){
        //code to show new content, works when launched through notification
    }
}

As far as I know the only way to find out if you receive a push notification is when the application is active and you receive the notification. 据我所知,找出是否收到推送通知的唯一方法是当应用程序处于活动状态并且收到通知时。

The application self can't access the received push notifications because those are handled by the os. 应用程序自身无法访问收到的推送通知,因为这些推送通知是由操作系统处理的。 So I'm afraid the answer is no, you can't... 所以,恐怕答案是否定的,你不能...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM