How to display a notification in worklight when returning to the foreground?

427 views Asked by At

I am using push notification in worklight 6.2 in one of my apps.

I have a issue regarding receiving of notification. i receive notification when i am in the application .

When i close my app or made my app go background, i receive notification in the status bar and when i click on that,its taking me to the app ask for the authentication which is provided in the app and then goes to the inbox where all the messages are listed the new message is displayed .

But when i receive the notification when my apps is in background and see the notification in status bar and without clicking that notification if i opened the application and see the inbox page ,the message is not displayed because the function which will be executed when receiving notification is not called.

I need to give solution to avoid this. Is there any way or option to display the notification which is received when the app is in background and when the app is opened without opening the notification in status bar.

Thanks in advance

1

There are 1 answers

9
Idan Adar On BEST ANSWER

Perhaps you could use a the Cordova resume event, from which you will call the pushNotificationReceived() function as the callback function.

document.addEventListener("resume", pushNotificationReceived, false);

The basic premise is that if a notification was received while you were in the background, then once returning to the foreground the above should executed and the notification will be displayed.

Again, this is just the basic premise and you'll probably need to modify the pushNotificationReceived() implementation to account for what happens when you get back to the foreground but there are no notification (you could implement some logic to check that...) and various other scenarios, as you encounter them.