[英]Handle pushbots notification clicked in angularjs controller in PhoneGap app
[英]Pushbots handle notification while Phonegap app is open
我有一個PhoneGap應用程序,該應用程序已經在onDeviceReady事件中設置了Pushbots。
如果該應用程序未在后台運行,但如果該應用程序正在運行並且正在使用中,並且用戶放下通知選項卡並單擊通知,則沒有任何反應, 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中有一個$ rootScope.onNotificationClick事件。 我是否應該以某種方式實例化/將Pushbotsplugin傳遞給該控制器?
您是在單擊通知時發出事件的。 因此,您可以使用以下代碼在控制器中處理$ on
$rootScoope.$on('onNotificationClick', function (data) {
// handle here.
//need not pass pushBotPlugin
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.