Reputation: 636
I have multiple iBeacons with the same UUID but different major and minor numbers. It can be different combinations for major and minor, but the UUID stays the same. Say for example,
Also, these iBeacons are located in close proximities, ranging from 1 - 50 feet. Therefore, their regions can intersect with each other.
In my iOS app, I want to detect all the iBeacons with the same UUID in the area and then iterate through them and read major and minor of each to detect which one of them have been detected.
Can I use
init(proximityUUID: UUID,
identifier: String)
with my UUID and then iterate through them ?
Upvotes: 1
Views: 1818
Reputation: 64916
There are two different iOS CoreLocation APIs and you'll need to use the first one for this purpose:
1. Beacon Ranging (What you want)
You call locationManager.startRangingBeacons(in: region)
with a region definition that leaves major and minor nil. The constructor you show init(proximityUUID: UUID,
identifier: String)
does exactly that.
This will give you a callback to locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion)
one time per second with an array of all CLBeacon
objects that match your region definition. You can iterate over this array to see all of them.
2. Beacon Monitoring (What you do not want)
You call locationManager.startMonitoring(region: region)
with a region definition that leaves major and minor nil.
This will give you a callback to locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion)
or the equivalent didExitRegion method each time at least one beacon matching the region definition appears, or all the beacons matching the region disappear.
This will not let you iterate over all matching beacons as the callback only includes the region definition not the list of matched beacons.
Upvotes: 2
Reputation: 1137
Yes you definitely can! You will not get new delegate notifications when another iBeacon is detected unless you create multiple listeners with different IDs but once you are in the Region of a given UUID, you can iterate through all beacons within range and get their major and minor
Upvotes: 1