簡體   English   中英

未定義Cordova aerogear-push android push

[英]Cordova aerogear-push android push is not defined

我正在嘗試使用aerogear推送通知插件在Cordova上構建一個簡單的應用程序

我正在做的就是緊緊遵循本指南: https : //aerogear.org/docs/guides/aerogear-cordova/AerogearCordovaPush/#_sample_example

但是,將示例代碼放入我的js后,此行:

push.register(onNotification, successHandler, errorHandler, pushConfig);

由於未定義推送,將導致參考錯誤

我遵循了之前的所有步驟,並且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();

我解決了這個問題,因為該插件未正確安裝在我的應用程序中,並且安裝失敗,因為我缺少了為Android構建所需的google-service.json文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM