2016-09-22 61 views
0

我有一個PhoneGap應用程序,我已經設置了Pushbots(在onDeviceReady事件中)。Pushbots在Phonegap應用程序打開時處理通知

通知:點擊事件是否正常工作,如果應用程序沒有在後臺運行,但如果應用程序正在運行,它的使用,並且用戶帶來向下的通知選項卡,然後點擊一個通知,沒有什麼發生。

我該如何觸發通知:當應用處於前臺時點擊事件?

我想在用戶單擊通知時導航到頁面,無論應用程序是否正在運行。

我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以某種方式傳遞給該控制器?

回答

0

您在通知點擊時發出事件。因此,您可以使用以下代碼在控制器中處理$開:

$rootScoope.$on('onNotificationClick', function (data) { 
// handle here. 
//need not pass pushBotPlugin 
}); 
相關問題