katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

on click is not working if redirection added #788

Closed Gurudevdatta closed 7 years ago

Gurudevdatta commented 8 years ago

The notification and 'on click ' event works properly but if we add redirection after schedule , 'on click' event is not firing... This is my send reminder function.. function add_reminder(notify_list){ cordova.plugins.notification.local.hasPermission(function(granted){ if(granted == true){ cordova.plugins.notification.local.schedule(notify_list); }else{ cordova.plugins.notification.local.registerPermission(function(granted) { if(granted == true){ cordova.plugins.notification.local.schedule(notify_list); }else{ navigator.notification.alert("Reminder cannot be added because app doesn't have permission"); } }); } }); cordova.plugins.notification.local.on("click", function (notification, state) { alert(notification.id + " was clicked"); window.localStorage.setItem("not_sch_id",notification.id);
window.location.href='main.html'; }, this);
}

And the calling code is.. var sch_not_list=[]; msg="You have medication(s) to take now 00:00 XX" ; var schedule_time = new Date(('2015-12-16 14:48:00').replace(/-/g, "/")).getTime(); sch_not_list.push({id: 14,title: 'Medicine Reminder',text: msg,at: schedule_time});
add_reminder(sch_not_list); //..following line causes onclick not working window.location.href = "main.html";

...From above code if i remove the last "window.location.href = "main.html"; " the notification and the click event fires properly.

Can you please guide me on this?

katzer commented 8 years ago

@sangramkokate Without proper code formatting its impossible to read.

ghost commented 8 years ago

@sangramkokate - please use window.location.replace("main.html"); window.location.href is not gracefully supported in phonegap/cordova. White list your parent/base domain in the config.xml

Gurudevdatta commented 8 years ago

Thanks for your reply katzer ..but i am able to found the solution..the problem is that we need to provide ...cordova.plugins.notification.local.on("click", function (notification ) on redirection page ..so i need to put this on each page device ready to get it working.

ghost commented 8 years ago

@sangramkokate - instead of adding to every page device ready, why can't you add this event listener to app run config

rwillett commented 7 years ago

Is this an issue now or can this be closed?