I'm calling registerForPushNotifications when my app launches, and also when the user add's an item to their favorites, at which point I re-register, adding the id to the "tags" in their device token.
If the user gets a push notification and selects it to open the app, I have some code to display an alert box with the notification alert text. Which is fine.
The problem is if the user adds or removes items from the their favorites at that point (and registerForPushNotifications gets called again) it will display the same alert box again. This will continue to happen until the app is closed and shut down.
My registerForPushNotifications as follows:
function registerPush(tags){ Ti.Network.registerForPushNotifications({ types: [ Ti.Network.NOTIFICATION_TYPE_BADGE, Ti.Network.NOTIFICATION_TYPE_ALERT, Ti.Network.NOTIFICATION_TYPE_SOUND ], success:function(e) { var deviceToken = e.deviceToken; var params = { tags: tags, }; UrbanAirship.register(params, function(data) { //alert("registerUrban success: " + JSON.stringify(data)); }, function(errorregistration) { //alert("Couldn't register for Urban Airship"); }); }, error:function(e) { //alert("push notifications disabled: "+e); }, callback:function(e) { if (!e.data.options) { e.data.options = [{ name: 'Okay', }]; } var options = e.data.options; var buttonNames = []; for (var i = 0; i<options.length; i++) { buttonNames.push(options[i].name); } var a = Ti.UI.createAlertDialog({ title: e.data.title ? e.data.title : 'New Message', message: e.data.alert, buttonNames: buttonNames, }); a.addEventListener('click', function(e){ var option = options[e.index]; if (option) { if (option.url) { Ti.Platform.openURL(option.url); } } }); a.show(); } }); }So it seems like the callback function is getting called each time I run registerForPushNotifications after a notification is received. Shouldn't the callback only be called a notification is received like the documentation says? (http://docs.appcelerator.com/titanium/2.0/index.html#!/api/PushNotificationConfig-property-callback)
I get the feeling I'm missing something obvious.
Your Answer
Think you can help? Login to answer this question!