我已按照Pushwoosh 网站上建议的所有步骤进行操作,但仍然出现以下错误:
Uncaught TypeError: Cannot read property 'pushNotification' of undefined
请帮我!
有关我的代码的更多信息:
- “ https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin.git ”-> 我安装了插件源代码
- 将 config.xml 文件中的 *.pushwoosh.com 域列入白名单:->我没有这样做,因为 xdk 应该自动完成
3.注册推送通知:将以下函数添加到您的javascript文件中,输入正确的项目编号和Pushwoosh App 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