简体   繁体   English

未定义Cordova aerogear-push android push

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

I'm trying to build a simple application on cordova using aerogear push notification plugin 我正在尝试使用aerogear推送通知插件在Cordova上构建一个简单的应用程序

What i'm doing is following closely this guide: https://aerogear.org/docs/guides/aerogear-cordova/AerogearCordovaPush/#_sample_example 我正在做的就是紧紧遵循本指南: https : //aerogear.org/docs/guides/aerogear-cordova/AerogearCordovaPush/#_sample_example

However, after put the sample code in my js, this line: 但是,将示例代码放入我的js后,此行:

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

will cause a reference error since push is not defined 由于未定义推送,将导致参考错误

I followed all the step before and the aerogear-cordova-push plugin is in the folder of the plugins, maybe i require some additional steps to refer to the plugin? 我遵循了之前的所有步骤,并且aerogear-cordova-push插件位于插件的文件夹中,也许我需要一些其他步骤来引用该插件?

Also, the plugin provide an index.html as example inside its folder, but even using that i'm not able to resolve push 另外,该插件在其文件夹内提供了index.html作为示例,但即使使用该插件,我也无法解析推送

I tried to move the js files of the plugin in the www folder and linked them on index before the execution of index.js, since this it isn't very correct cause other reference errors 我试图将插件的js文件移到www文件夹中,并在执行index.js之前将它们链接到索引上,因为这不是很正确,会导致其他参考错误

The index.html on the www folder is the same that a standard cordova project provide after its creation www文件夹上的index.html与标准cordova项目创建后所提供的相同

This is my index.js, i'm able to show the error on android throught the try catch: 这是我的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