问题
I see this question Estimote: detecting multiple beacons with ESTBeaconRegion and startRangingBeaconsInRegion?
I try that answer provided but when I made three regions (eg: from that sample code beacon1Region, beacon2Region, beacon3Region) and include that "EstimoteSampleRegion" for each (eg: EstimoteSampleRegion1, EstimoteSampleRegion2, EstimoteSampleRegion3) I can only get first beacon as result (in index 0) when I startRangingBeaconsInRegion.
How can I make this to work? should I list that three estimote sample regions in one array that is all for a single region (eg: "beaconRegion") and then look in that single region for the three beacons with [self.beaconManager startRangingBeaconsInRegion:beaconRegion]?
If yes, what is code that show declare that array with many beacons for one region?
Or should I make three beaconManager Instances and each beacons has its own region? Problem when I do this is I can only see first beacon. not three.
回答1:
The reason why you get only first beacon is because you are ranging different regions and this is how iOS recognizes what are you looking for. Even using CoreLocation and one CLLocationManager you will get one beacon in array in delegate method.
You can add ranged beacon to your own array, which can be property in your model, for example.
Or should I make three beaconManager Instances and each beacons has its own region? Problem when I do this is I can only see first beacon. not three.
Yes, this can be done this way. You then implement
- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
and that method will be called one time for every beacon manager every 1 second. In current beacons
array there will be only one object but after all you get all of your beacons.
And the same as above, you can add ranged beacon to your own array, which can be property in your model, for example.
If your beacons have the same major number (and different minor numbers) you can the use this method:
[self.manager startRangingBeaconsInRegion:[[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:713 identifier:@"Multiple Beacons"]];
after that in
- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
you will get array with more than one beacon inside (of course if you have them near you iOS device).
来源:https://stackoverflow.com/questions/22340385/how-declare-estimote-array-for-many-beacons