[英]Cordova not defined in pushwoosh
我从这里开始关注pushwoosh的推送通知教程。
我在我的index.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.PushNotification”。
如果在配置文件中使用插件名称=“ pushwoosh-cordova-plugin”,则使用“ pushwoosh-cordova-plugin.PushNotification”
如果在配置文件中使用插件名称=“ pushwoosh-pgb-plugin”,则使用“ com.pushwoosh.plugins.pushwoosh.PushNotification”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.