我试图让我的chrome-cordova应用程序通过chrome.gcm api接收消息,但它不起作用,
控制台输出设备已注册,但当我尝试向该ID发送消息时,我什么都没得到,
这是我的background.js文件:
/**
* Listens for the app launching then creates the window.
* Ignores the provided window size.
*
* @see http://developer.chrome.com/trunk/apps/app.window.html
*/
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
width: 244,
height: 380,
});
});
var GCM_SENDERID = '224595526060';
var GCM_SENDER = GCM_SENDERID + '@gcm.googleapis.com';
(function main() {
var errorLogger = function() {
console.error.apply(console, arguments);
};
chrome.gcm.onSendError.addListener(errorLogger);
chrome.gcm.onMessagesDeleted.addListener(errorLogger);
chrome.gcm.onMessage.addListener(function(msg) {
console.info('got GCM message', msg);
});
chrome.gcm.register([GCM_SENDERID], function(regid) {
if (chrome.runtime.lastError || regid === -1) {
console.error(chrome.runtime.lastError);
return;
}
console.info('GCM connect success, reg', regid);
});
}());