aerogear プッシュ通知プラグインを使用して、cordova で簡単なアプリケーションを構築しようとしています。
私がやっていることは、このガイドに厳密に従っています: https://aerogear.org/docs/guides/aerogear-cordova/AerogearCordovaPush/#_sample_example
しかし、私のjsにサンプルコードを入れた後、この行:
push.register(onNotification, successHandler, errorHandler, pushConfig);
push が定義されていないため、参照エラーが発生します
前のすべての手順に従いましたが、aerogear-cordova-push プラグインはプラグインのフォルダーにあります。プラグインを参照するには追加の手順が必要でしょうか?
また、プラグインはそのフォルダー内の例として index.html を提供しますが、それを使用してもプッシュを解決できません
プラグインの js ファイルを www フォルダーに移動し、index.js の実行前にインデックスにリンクしようとしましたが、これはあまり正しくないため、他の参照エラーが発生します。
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();