Open LiamChapman opened 8 years ago
I think I've fixed it. I wasn't defineing the BeaconRegion correctly and passing it my ranging methods correctly. Here is what my code looks like now more or less:
// All Beacons to track
var Beacons = [
{
uuid : 'xxxxx',
identifier : 'Pink',
minor : 1,
major : 1
},
{
uuid : 'xxxxx',
identifier : 'Blue',
minor : 2,
major : 1
},
{
uuid : 'xxxxx',
identifier : 'Green',
minor : 3,
major : 1
}
];
var BeaconRegions = [];
// loop Beacons to be used.
for (var i in Beacons) {
var b = Beacons[i];
BeaconRegions[b.identifier] = new cordova.plugins.locationManager.BeaconRegion(b.identifier, b.uuid, b.major, b.minor);
}//end for
// Beacon Plugin Delegation
var delegate = new cordova.plugins.locationManager.Delegate();
delegate.didStartMonitoringForRegion = function (result) {
// Log to Xcode
cordova.plugins.locationManager.appendToDeviceLog(">>> START " + JSON.stringify(result));
};
delegate.didEnterRegion = function (result) {
// Log to Xcode
// cordova.plugins.locationManager.appendToDeviceLog(">>> ENTER " + JSON.stringify(result));
console.log(">>>|| ENTER DEBUG ||<<<", result.region.identifier);
// Start Ranging Beacon When it enters Inside Region
cordova.plugins.locationManager.startRangingBeaconsInRegion(BeaconRegions[result.region.identifier])
.fail(console.error)
.done();
};
delegate.didExitRegion = function (result) {
// Log to Xcode
// cordova.plugins.locationManager.appendToDeviceLog(">>> EXIT " + JSON.stringify(result));
console.log(">>>|| EXIT DEBUG ||<<<", result.region.identifier);
// Stop Ranging Beacon if Outside Region
cordova.plugins.locationManager.stopRangingBeaconsInRegion(BeaconRegions[result.region.identifier])
.fail(console.error)
.done();
};
delegate.didDetermineStateForRegion = function (result) {
// Log to Xcode
// cordova.plugins.locationManager.appendToDeviceLog(">>> DETERMINE " + JSON.stringify(result));
console.log(">>>|| DETERMINE DEBUG ||<<<", result.region.identifier);
};
delegate.didRangeBeaconsInRegion = function (result) {
// Log to Xcode
// cordova.plugins.locationManager.appendToDeviceLog(">>> RANGE " + JSON.stringify(result));
console.log(">>>|| RANGE DEBUG ||<<<", result.region.identifier, result.beacons[0].proximity);
};
// Set Methods for Location Manager
cordova.plugins.locationManager.setDelegate(delegate);
// Ask/Check For Permission
cordova.plugins.locationManager.requestAlwaysAuthorization();
// Loop BeaconRegions to setup region monitoring.
for (var i in BeaconRegions) {
var b = BeaconRegions[i];
if (b == undefined) continue;
cordova.plugins.locationManager.startMonitoringForRegion(b);
}
You can also track on UUID without setting major and minor IDs, and then handle the distinction in software. That's how I do it in CliqTags Beacon Reader.
I was doing this by just passing the major through, and leaving the minor undefined. It works great on Android. However, on iOS, it seems to depend on the direction of the wind or something, because it would work one day and not the next.
I always use major and minor wildcards. That no doubt works.
I wish also UUID could be wildcard.
Yeah, that's what I'm doing now. However, I wish I could set a major and leave the minor as a wildcard. Doing that seems to work on Android, but not on iOS.
I tried the way explained by LiamChapman commented on Nov 26, 2015 , but its not ranging or detecting multiple beacons , it's detecting only one.
Hi All,
The library works perfectly with one beacon, but i need to monitor several. I've looked through the issues on this project on how to do this, but it seems out of date and not to be working. It seems to start monitoring the beacons. However, in the console it only returns the determined state of one beacon.
Below is the code I currently have in place. If anyone has any suggestions or tips I'd greatly appreciate it!
Thanks,
Liam