Javascript 未定义Cordova aerogear推送android推送
我正在尝试使用aerogear推送通知插件在cordova上构建一个简单的应用程序 我所做的是严格遵循本指南: 但是,将示例代码放入my js后,这一行:Javascript 未定义Cordova aerogear推送android推送,javascript,android,cordova,push-notification,aerogear,Javascript,Android,Cordova,Push Notification,Aerogear,我正在尝试使用aerogear推送通知插件在cordova上构建一个简单的应用程序 我所做的是严格遵循本指南: 但是,将示例代码放入my js后,这一行: push.register(onNotification, successHandler, errorHandler, pushConfig); 将导致引用错误,因为未定义推送 我遵循了之前的所有步骤,aerogear cordova push插件位于插件文件夹中,也许我需要一些额外的步骤来引用插件 此外,插件在其文件夹中提供了index.
push.register(onNotification, successHandler, errorHandler, pushConfig);
将导致引用错误,因为未定义推送
我遵循了之前的所有步骤,aerogear cordova push插件位于插件文件夹中,也许我需要一些额外的步骤来引用插件
此外,插件在其文件夹中提供了index.html作为示例,但即使使用它,我也无法解析推送
我试着在www文件夹中移动插件的js文件,并在index.js执行之前将它们链接到index上,因为这样做不太正确,会导致其他引用错误
www文件夹上的index.html与标准cordova项目创建后提供的相同
这是我的index.js,我可以通过try-catch在android上显示错误:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
try {
app.receivedEvent('deviceready');
var pushConfig = {
pushServerURL: "...",
android: {
senderID: "...",
variantID: "...",
variantSecret: "..."
}
};
push.register(app.onNotification, successHandler, errorHandler, pushConfig);
}
catch (e){
alert(e);
}
function successHandler() {
console.log('success')
}
function errorHandler(message) {
console.log('error ' + message);
}
},
onNotification: function(event) {
alert(event.alert);
},
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}}; app.initialize();
我解决了这个问题,因为插件在我的应用程序中安装不正确,安装会失败,因为我缺少为android构建所需的google-service.json文件我解决了这个问题,因为插件在我的应用程序中安装不正确,安装会失败,因为我缺少为android构建所需的google-service.json文件