[英]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.