petermetz / cordova-plugin-ibeacon

An iBeacon plugin for Phonegap / Cordova 3.x and upwards. Supports both iOS and Android (contributions are welcome)
Apache License 2.0
726 stars 373 forks source link

The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect() #293

Open HuoJiazhi opened 7 years ago

HuoJiazhi commented 7 years ago

When I run my hybrid app in my phone(Android),I can not get the beacons and get the Exception: “The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()”

here is my index.js:

var app = {
    initialize: function() {
        document.addEventListener('deviceready',this.onDeviceReady.bind(this), false);
    },
    onDeviceReady: function() {
        var beacons = [];
        var uuid = 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0';
        var identifier = 'BrightBeacon';

        var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid);

        var delegate = new cordova.plugins.locationManager.Delegate();

        delegate.didRangeBeaconsInRegion = function (pluginResult) {
            beacons = pluginResult.beacons;
            console.log(pluginResult);
        };

        cordova.plugins.locationManager.setDelegate(delegate);

        cordova.plugins.locationManager.startRangingBeaconsInRegion(beaconRegion)
            .fail(function(e) {alert(e);})
            .done();
        this.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;');

        console.log('Received Event: ' + id);
    }
app.initialize();
ibuioli commented 6 years ago

Same problem here! Any news?

Edit with solution: Like when you use the accelerometer, you need to wait a few second before call the beacon. The quick solution is use a setTimeOut (I tested with 3000 ms, but with 1000 ms have to works).