GCM向每个用户发送多个通知 - 收到多个通知的Cordova推送通知

时间:2016-06-02 06:43:20

标签: perl ionic-framework push-notification google-cloud-messaging ngcordova

我正在使用离子应用,其中管理员向特定群组中的应用用户发送通知。对于android,GCM api与perl scripts一起使用,作为cron作业运行。 cron作业只是获取组中的所有用户,并向他们发送通知。

问题: 如果我向一组人发送消息,来自cron作业的日志显示消息被发送一次给每个用户,但$ cordovaPush:notificationReceived监听器不止一次接收消息,有时它有8个通知。

Cordova推送代码 它只是一个简单的倾听者,因为它在文档中提到过。

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
switch(notification.event)
            {
                case 'registered': // device is registered with GCM
                    if (notification.regid.length > 0 ) {
                        $log.debug('registration ID = ' + notification.regid);

                        $rootScope.device_token = notification.regid;
                        window.localStorage.setItem(LOCAL_STORAGE_KEY.device_token, notification.regid);
                        window.localStorage.setItem(LOCAL_STORAGE_KEY.is_push_enabled, true);

                        var new_param_object = {};
                        new_param_object[LOCAL_STORAGE_KEY.network_type] = network_type;
                        new_param_object[LOCAL_STORAGE_KEY.device_token] = notification.regid;
                        new_param_object[LOCAL_STORAGE_KEY.user_email] = window.localStorage.getItem(LOCAL_STORAGE_KEY.user_email) || 'unknown registered';
                        new_param_object[LOCAL_STORAGE_KEY.auth_token] = window.localStorage.getItem(LOCAL_STORAGE_KEY.auth_token) || 'unknown registered';
                        registerDevice(user_email,$rootScope.device_token,register_from, network_type, auth_token);
                    }
                    break;

                case 'message': // There is a message!!
                    $rootScope.is_inbox_stale = true;
                    if(notification.foreground == "1")
                    {
                        $log.debug("Notification received when app was opened (foreground = true)", notification.message);
                    }
         }
}

Perl脚本 正如我提到的日志,我认为脚本运行正常。

问题是: 有什么东西我做得不对,或者这是GCM或cordova推送通知的常见行为吗? 任何形式的帮助将不胜感激。

0 个答案:

没有答案