我已经遵循了Pushwoosh网站上建议的所有步骤,但仍然会出现以下错误:
Uncaught TypeError: Cannot read property 'pushNotification' of undefined,请帮帮我!
有关我的代码的更多信息:
3.注册推送通知:在javascript文件中添加以下函数,输入正确的项目编号和Pushwoosh应用程序ID
$( document ).ready(function() {
// Handler for .ready() call
initPushwoosh();
}
//push begin
function initPushwoosh(){
var pushNotification = window.plugins.pushNotification;
//set push notifications handler
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
alert(title);
});
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({ projectid: "****", appid : "****" });
//register for pushes
pushNotification.registerDevice(
function(status) {
var pushToken = status;
console.warn('push token: ' + pushToken);
},
function(status) {
console.warn(JSON.stringify(['failed to register ', status]));
}
);
}
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
console.warn('user data: ' + JSON.stringify(userData));
alert(title);
});
//push end
发布于 2014-09-23 11:03:24
检查window.plugins.pushNotification是否为空或未定义。
如果它是null (或未定义),请确保在config.xml中引用插件正确("phonegap“命令应该自动为您完成一切)。
如果你提供更多的信息,我可以改进答案。
https://stackoverflow.com/questions/25990325
复制相似问题