Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Handling push: identify when app is in the foreground

I want a confim dialog to appear when a push arrives, but only do this when the app is active in the foreground. When the app is not active and the push appears in the status bar, I do not want the confirm dialog to appear.

This is my code, which I am executing when a push notification arrives:

pre
navigator.notification.beep(1);

function onConfirm(buttonIndex) {
if (buttonIndex === 2) {
jQuery.mobile.pageContainer.pagecontainer('change', 'news.html', {
allowSamePageTransition: false,
transition: 'none',
reload: true
});
}
}

navigator.notification.confirm(
'The school has just posted some news. Would you like to read it now?', // message
function(buttonIndex) {
onConfirm(buttonIndex);
}, // callback
'School News', // title
['Cancel', 'Read it now'] // labels
);
/pre

What do I need to add to ensure this only runs when the app is in the foreground, or to ensure that something else happens when clicking the a push in the status bar?

Thanks!

Chris

Return to “Issues”