iphone - Preventing every push notification being executed iOS titanium -
iphone - Preventing every push notification being executed iOS titanium -
if multiple force notifications whilst app in foreground. callback method execute every force notification 1 one.
callback : function(e) { if (e.inbackground == 1) { //came background - something. } else { // titanium.ui.iphone.setappbadge(null); //check type, if chat. if (type == 'chat') { //check if window opened or not, if fire event handler if (currentwindow == '_chatwindow') { //update view straight after entering app background. fire event handler ti.app.fireevent('_updatechat', {}); } else if (currentwindow == '_messages') { //refresh messages screen if on messages screen , chat message arrives //update view straight after entering app background. fire event handler ti.app.fireevent('_updatemessages', {}); } else { //display local notification } }
if force notification has come background easy deal with, force notification activated 1 user chooses swipe. however, if multiple force notifications come foreground , it's chat, execute them multiple times.
how can handle force notifications in foreground better? thanks
update:
tried code without much luck
ti.app.addeventlistener('_displaynotification', function(e) { //store force notifications in array var pusharray = []; var countpushnotifications; //currenttime cross reference var currenttime = new date(); if (currenttime - alloy.globals.pushtime < 3000) { //do pusharray.add(e.pushnotificationdata); } else { //after 3 seconds remove event handler //fire event filter array , process notification, reset time next event alloy.globals.pushtime = null; ti.app.removeeventlistener('_displaynotification', {}); } //first force notification, current time if(alloy.globals.pushtime==null){ alloy.globals.pushtime = currenttime; } });
trying force notifications within array, farther filtering.
update 2:
if (alloy.globals.countpushnotificationsflag == 1) { alloy.globals.countpushnotificationsflag = null; settimeout(function() { ti.app.fireevent('_displaynotification', { pushmessage : message }); }, 6000); } else { alloy.globals.countpushnotificationsflag = 1; ti.app.fireevent('_displaynotification', { pushmessage : message }); }
i have tried execute force notifications alternatively.
1st notification - fires instantly. 2nd notification - fires after 6 seconds. 3rd notification - instantly. 4th notification - fires after 6 seconds.
and on...
however code works
notification 1 , 2.
fails when hits 3rd notification.
you can check if force received in foreground or background using inbackground property of force here documentation
hope helps.
ios iphone notifications titanium titanium-alloy
Comments
Post a Comment