首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pushbots在Phonegap应用程序打开时处理通知

Pushbots在Phonegap应用程序打开时处理通知
EN

Stack Overflow用户
提问于 2016-09-22 10:56:41
回答 1查看 330关注 0票数 0

我有一个PhoneGap应用程序,我已经安装了Pushbots (在onDeviceReady事件中)。

如果应用程序没有在后台运行,notification:clicked事件就能正常工作,但是如果应用程序正在运行,并且正在使用,并且用户打开通知选项卡并单击通知,则什么都不会发生。

当应用程序位于前台时,我如何触发notification:clicked事件?

无论应用程序是否正在运行,只要用户单击通知,我都想导航到页面。

我的index.js文件

代码语言:javascript
复制
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实例化/传递给该控制器?

EN

回答 1

Stack Overflow用户

发布于 2016-09-25 13:08:58

您将在通知单击时发出该事件。因此,您可以使用以下代码在控制器中处理$on

代码语言:javascript
复制
$rootScoope.$on('onNotificationClick', function (data) {
 // handle here.
 //need not pass pushBotPlugin
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39637134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档