GCM邮件未收到Chrome Packaged Apps(离线模式) [英] GCM messages not getting delivered to Chrome Packaged Apps(offline mode)

查看:145
本文介绍了GCM邮件未收到Chrome Packaged Apps(离线模式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 https://github.com/ToothlessGear/node-gcm 发送如果Chrome应用程序正在运行,一切正常。



当我发送消息时Chrome应用程序关闭时的消息,这些消息在启动应用程序后不会传递。我在服务器端得到了message_id。



我也尝试过使用命令行,在命令行中也遇到同样的问题。



在服务器端的代码(nodejs)

  var GCM = require('node-gcm'); 
var gcmSender = new GCM.Sender(apiKey);
var sendGCMMessage = function(data,regIds,collapseKey,callback){

var message = new GCM.Message({
priority:'high',
collapseKey :collapseKey,
data:data
});

gcmSender.send(message,regIds,
function(err,result){
callback(err,result)
})

}

打包的应用程式:

  //注册

var senderIds = [senderId];
chrome.gcm.register(senderIds,function(registrationId){

sendRegistrationIdToServer(registrationId,function(succeed){

});
} );

//监听传入消息

chrome.gcm.onMessage.addListener(函数(消息){
console.log(gcm message)
});


解决方案

问题在于我假设铬行为。



如果chrome正在运行(并且应用程序已关闭),则Chrome会显示GCM消息。 chrome会唤醒应用程序并运行onMessage侦听器,因为注册发生在background.js中。否则该消息被丢弃。

在我的情况下,我没有在backgroud.js中进行注册。将我的注册移至backgroud.js,现在工作正常。


I am using https://github.com/ToothlessGear/node-gcm to send message using GCM to chrome packaged apps.

Everything works fine if chrome app is running

When I am sending the message while chrome app is closed, those messages are not delivered after starting the app. I do get the message_id in the result at server.

I also tried using command line, facing the same problem in command line too.

Code at server side(nodejs)

var GCM = require('node-gcm');
var gcmSender = new GCM.Sender(apiKey);
var sendGCMMessage = function(data, regIds, collapseKey, callback) {

                var message = new GCM.Message({
                    priority: 'high',
                    collapseKey: collapseKey,
                    data: data                  
                });

                gcmSender.send(message, regIds, 
                    function(err, result) {
                    callback(err, result)
                })

    }

Packaged Apps:

//register 

var senderIds = [senderId];
chrome.gcm.register(senderIds, function(registrationId) {

    sendRegistrationIdToServer(registrationId, function(succeed) {

    });
});

    //listen to incoming messages

chrome.gcm.onMessage.addListener(function(message) {
   console.log("gcm message")        
});

解决方案

The problem was the way I was assuming the chrome behaves.

In chrome the GCM message is delivered if chrome is running(and app is closed). chrome wakes up the app and run the onMessage listener, given that the registration took place in the background.js. Or else the message is discarded.

In my case I was not doing the registration in backgroud.js. Moved my registration to backgroud.js and it is working fine now

这篇关于GCM邮件未收到Chrome Packaged Apps(离线模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆