您好我按照以下步骤
1)我创建了cordova项目结构 2)我添加了平台(android) 3)我添加了cordova插件
cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0
4)对cordova项目进行建设
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.
}
};
我正在等待#34;好的"。我无法打电话给'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().
答案 0 :(得分:0)
这是推送通知流程:
您必须遵循所有这些步骤才能使推送通知有效。
对于android,您需要在通知处理程序的registered
事件中捕获注册ID(令牌):
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
console.log("regID = " + e.regid);
// save/send this registration id on your server
} else if('error' === e.event) {
// Failed to register device.
}
};
对于iOS,您需要在register
函数的succesHandler中捕获它。
有关详细信息,请查看this example in the plugin repository。