来自cordova插件的服务不再启动了

时间:2016-08-26 08:07:38

标签: android cordova npm ibeacon ibeacon-android

我一年前用这个插件https://www.npmjs.com/package/cordova-plugin-beacon来检测附近的ibeacons。那个旧的应用程序仍然有效。出于某种原因,如果我今天使用cordova创建相同的应用程序,我看到该插件已初始化并开始监控(在电话上),但就此而言。我什么也得不到。

我相信cordova的新结构不再将插件注册为服务,并且android并没有将其视为一种服务。因此,它不会通过蓝牙监听任何变化。

我在旧清单和新清单中看到了这一点:

旧: enter image description here

新: enter image description here

正如您所看到的,src结构也不同。可能是什么问题?

编辑:我在两个应用程序中都有相同的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() {
    app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
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;');

    var logToDom = function (message) {
        var e = document.createElement('label');
        e.innerText = message;

        var br = document.createElement('br');
        var br2 = document.createElement('br');
        document.body.appendChild(e);
        document.body.appendChild(br);
        document.body.appendChild(br2);

        window.scrollTo(0, window.document.height);
    };

    var initializeBluetooth = cordova.plugins.simplexpbeacon.initialiseBluetooth(function(data){
        var json = JSON.parse(data);
        logToDom(JSON.stringify(json));
    });

    var monitor = cordova.plugins.simplexpbeacon.startMonitoring(
        function(data) {
            var json = JSON.parse(data);
            logToDom(JSON.stringify(json));
            /*if (json.status === 'OK') {
            logToDom(JSON.stringify(json));
            }*/
        }
    );

    initialiseBluetooth();
    monitor();


    console.log('Received Event: ' + id);
}
};

app.initialize();

0 个答案:

没有答案