can you intercept a push notification if you app is open, so that you can get the message sent using the notification and perform some task. How can this be implemented in titanium?
1 Answer
After you register (in my example for Urban Airship), when a Push comes in you get a callback, I deal with it like this:
function messageCallback(e) { var message; Ti.API.info('messageCallback e:' + JSON.stringify(e)); if(e.data.aps != undefined) { if(e.data.aps.alert != undefined){ if(e.data.aps.alert.body != undefined){ message = e.data.aps.alert.body; } else { message = e.data.aps.alert; }; } else { message = 'No Alert content'; }; } else { message = 'No APS content'; }; var alertDialog = Titanium.UI.createAlertDialog({ title:'Notification', message:message, buttonNames: ['OK'] }); alertDialog.show(); };Bear in mind Apple does not let you send data in the push notification, it's only really a prompt for the user to open the app.. From inside the app, I suppose you could call a web-service to find for that UserID what the message was all about and react..
Apple's reason for not allowing data apparently is that a push notification is not guaranteed to reach a device therefore cannot be relied upon in that way..
Your Answer
Think you can help? Login to answer this question!