【发布时间】:2015-09-12 08:01:31
【问题描述】:
您好,我按照以下步骤操作
1) 我创建了 cordova 项目结构。
2) 我添加了平台(android)。
3)我添加了cordova插件
cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0
4) 构建科尔多瓦项目。
5) 接下来我在 android eclipse(4.4.2) 中导入创建的应用程序
6)我在index.js文件中写了下面的代码
init: function(){
alert("init");
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler,
{
'senderID':'XXXXXXXXXX',
'ecb':'onNotificationGCM' // callback function
}
);
function successHandler(result) {
console.log('Success: '+ result);
alert(result);
}
function errorHandler(error) {
console.log('Error: '+ error);
}
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
}
else if('error' === e.event) {
// Failed to register device.
}
};
我得到的响应是“OK”。我无法调用 'ecb': onNotificationGCM' // 回调函数
在 Android 控制台中,我收到以下消息
V/PushPlugin(2512): execute: action=register
V/PushPlugin(2512): execute: data= [{"senderID":"889953963751","ecb":"onNotificationGCM"}] V/PushPlugin(2512): execute: jo={"senderID":"889953963751","ecb":"onNotificationGCM"} V/PushPlugin(2512): execute: ECB=onNotificationGCM senderID=889953963751
09-12 03:13:33.453: D/GCMRegistrar(2512): resetting backoff for com.ensis.hello
09-12 03:13:33.613: V/GCMRegistrar(2512): Registering app com.ensis.hello of senders 889953963751
09-12 W/PluginManager(2512): THREAD WARNING: exec() call to PushPlugin.register blocked the main thread for 181ms. Plugin should use CordovaInterface.getThreadPool().
【问题讨论】:
-
您在 GCM 中注册了吗?
-
是的,我已经注册了
-
您获得 GCM 注册 ID 了吗?
-
不,我没有得到任何 GCM 注册 ID,我正在发送 senderID
标签: android cordova phonegap-plugins