【发布时间】:2015-12-01 06:06:20
【问题描述】:
我在移动设备中使用 PubNub 推送通知。我为我的项目使用了以下代码。根据以下链接的指示。
var pushNotification = window.plugins.pushNotification;
pushNotification.register(
successHandler,
errorHandler,
{
'senderID':'projectID'
}
);
function successHandler(result) {
alert('Success: '+ result);
}
function errorHandler(error) {
alert('Error: '+ error);
}
但是这个推送通知寄存器调用了errorHandler函数。它显示错误消息“找不到类”。
为什么会出现这个错误?
请大家推荐
新更新
根据上面的链接,我在我的 cordova 项目中添加了以下代码。
function initialize() {
bindEvents();
}
function bindEvents() {
document.addEventListener('deviceready', init, false);
}
function init() {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler, {'senderID':'projectID','ecb':'onNotificationGCM'});
// Get your Sender ID at cloud.google.com/console
}
function successHandler(result) {
alert('Success: '+ result);
}
function errorHandler(error) {
alert('Error: '+ error);
}
function onNotificationGCM(e) {
switch( e.event ){
case 'registered':
if ( e.regid.length > 0 ){
console.log('regid = '+e.regid);
alert(e.regid);
}
break;
case 'message':
console.log(e);
if (e.foreground){
alert('The room temperature is set too high')
}
break;
case 'error':
alert('Error: '+e.msg);
break;
default:
console.log('An unknown event was received');
break;
}
}
initialize();
我在模拟器上运行这段代码。它只是成功调用successHandler 函数"OK"。它没有调用回调函数onNotificationGCM,我也没有得到注册的ID。
我的科尔多瓦项目代码背后的实际问题是什么。
请给我建议
【问题讨论】:
标签: cordova push-notification cordova-plugins