问题
Beginner Estimote question: What is the correct approach for adding multiple Estimote beacons, with their respective major/minors, so that all beacons can be detected separately using startRangingBeaconsInRegion?
This code works fine for a single beacon:
// Single Beacon Region
ESTBeaconRegion* beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
major:11111 minor:11111
identifier: @"EstimoteSampleRegion"];
// Start ranging beacons
[self.beaconManager startRangingBeaconsInRegion:beaconRegion];
However this code does not work for multiple beacons:
// Beacon 1 Region
ESTBeaconRegion* beacon1Region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
major:11111 minor:11111
identifier: @"EstimoteSampleRegion"];
// Beacon 2 Region
ESTBeaconRegion* beacon2Region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
major:22222 minor:22222
identifier: @"EstimoteSampleRegion"];
// Beacon 3 Region
ESTBeaconRegion* beacon3Region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
major:33333 minor:33333
identifier: @"EstimoteSampleRegion"];
// Start ranging beacons
[self.beaconManager startRangingBeaconsInRegion:beacon1Region];
[self.beaconManager startRangingBeaconsInRegion:beacon2Region];
[self.beaconManager startRangingBeaconsInRegion:beacon3Region];
With this code only the last beacon is detected. (So in this case, only beacon3Region is detected).
—
If you know how to add and detect multiple beacons with ESTBeaconRegion and startRangingBeaconsInRegion I would appreciate a code example that explains how to do this.
回答1:
Easy fix! Your identifier: @"EstimoteSampleRegion"]
must use a different string for all three regions.
This is true whether using the Estimote SDK or standard iOS CoreLocation
APIs, around which the Estimote SDK is just a thin wrapper. CoreLocation
keeps track of multiple regions by using that string identifier as a key. If you use the same string more than once, you are effectively telling CoreLocation
to replace one region with another region.
Shameless plug: if you use my company's ProximityKit framework, you do not have to manage your beacon regions at all in code -- you can do so dynamically in the cloud. You then no longer have to worry about keeping this identifier unique. It is compatible with Estimote beacons as well as all standard iBeacons, too.
来源:https://stackoverflow.com/questions/22325079/estimote-detecting-multiple-beacons-with-estbeaconregion-and-startrangingbeacon