我有一个PhoneGap应用程序,我已经安装了Pushbots (在onDeviceReady事件中)。
如果应用程序没有在后台运行,notification:clicked事件就能正常工作,但是如果应用程序正在运行,并且正在使用,并且用户打开通知选项卡并单击通知,则什么都不会发生。
当应用程序位于前台时,我如何触发notification:clicked事件?
无论应用程序是否正在运行,只要用户单击通知,我都想导航到页面。
我的index.js文件
myApp.run(['$rootScope', function($rootScope) {
document.addEventListener('deviceready', function() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
window.plugins.PushbotsPlugin.initialize(...);
window.plugins.PushbotsPlugin.on("registered", function(token){
console.log("Registration Id:" + token);
});
window.plugins.PushbotsPlugin.getRegistrationId(function(token){
console.log("Registration Id:" + token);
});
// Should be called once app receive the notification
window.plugins.PushbotsPlugin.on("notification:received", function(data){
alert("received:" + JSON.stringify(data));
console.log("received:" + JSON.stringify(data));
});
// Should be called once the notification is clicked
window.plugins.PushbotsPlugin.on("notification:clicked", function(data){
alert("Notification clicked"); only fires when the app is not running
$rootScope.$emit('onNotificationClick', data);
console.log("clicked:" + JSON.stringify(data));
});
}, false);
}]);我的MainAppController中有一个MainAppController事件。我是否应该以某种方式将Pushbotsplugin实例化/传递给该控制器?
发布于 2016-09-25 13:08:58
您将在通知单击时发出该事件。因此,您可以使用以下代码在控制器中处理$on
$rootScoope.$on('onNotificationClick', function (data) {
// handle here.
//need not pass pushBotPlugin
});https://stackoverflow.com/questions/39637134
复制相似问题