简体   繁体   中英

detect if push notification is waiting phonegap

I'm using the pushplugin with phonegap to send/ receive push notifications.

I'm wondering if there is a way to detect this scenario (android and 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:

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:

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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