我从这里开始按照推送通知教程进行操作。
我已将以下js函数添加到我的索引.js文件中。
function initPushwoosh()
{
var pushNotification = cordova.require("pushwoosh-cordova-plugin.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_NUMBER", pw_appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({ projectid: "XXXXXXXXX", pw_appid : "XXXXXXXX" });
//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]));
}
);
}
我已经成功添加了插件。但是该应用程序无法在设备上运行,并且在浏览器中我收到以下消息:
Uncaught ReferenceError: cordova is not defined
如何克服这个问题?
在 PushWoosh 的示例应用程序中,他们需要"com.pushwoosh.plugins.pushwoosh.PushNotification"cordova 插件,但在文档中,他们使用"pushwoosh-cordova-plugin"。推送通知"。
如果您在配置文件中使用插件名称="pushwoosh-cordova-plugin",请使用"pushwoosh-cordova-plugin"。推送通知"
如果您在配置文件中使用插件名称="pushwoosh-pgb-plugin",请使用"com.pushwoosh.plugins.pushwoosh.PushNotification"