I am working with iBeacons. I have multiple beacons, each beacon having the same UUID, major, but different minor values. Both the devices are ranged but they are not received together, the - locationManager:didRangeBeacons:inRegion: delegate callback "beacons" array contains only 1 beacon at a time.
I got to know that using multiple regions will have callback separately
This is how code for monitoring and ranging beacons
// Initialize and monitor regions
for (NSString *serviceUUID in _serviceUUIDs) {
// Initialize region
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:serviceUUID];
CLBeaconRegion *appBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:minor identifier:identifier];
// Specify notifications
appBeaconRegion.notifyEntryStateOnDisplay = YES;
appBeaconRegion.notifyOnEntry = YES;
appBeaconRegion.notifyOnExit = YES;
// Add to regions
[_appBeaconRegions addObject:appBeaconRegion];
// Begin monitoring region and ranging beacons
[_locationManager startMonitoringForRegion:appBeaconRegion];
[_locationManager startRangingBeaconsInRegion:appBeaconRegion];
}
I want to have all the beacons which are in range within single callback
How do i use single region with different minor, identifier values for all the beacons
Any help appreciated..
Thanks
You may use BeaconManagerDelegate
's didFindBeacon
callback to observe beacons nearby. This will get all beacons if they have the same UUID.
This is the code I wrote for this purpose:-
// in ApplicationdidFinishLaunchingWithOptions
let beaconID = NSUUID(UUIDString: "ADBD15B8-9A2F-492F-BB26-C7C92E05CAD3")
let regionIdentifier = "humra.ibeacons"
let beaconRegion = CLBeaconRegion(proximityUUID: beaconID!, identifier: regionIdentifier)
if locationManager.respondsToSelector("requestAlwaysAuthorization")
{
locationManager.requestAlwaysAuthorization()
}
locationManager.delegate=self
locationManager.pausesLocationUpdatesAutomatically=false
locationManager.startMonitoringForRegion(beaconRegion)
locationManager.startRangingBeaconsInRegion(beaconRegion)
locationManager.startUpdatingLocation()
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
NSLog("didRangeBeacons");
let message:String = ""
if(beacons.count > 0) {
let nearestBeacon:CLBeacon = beacons[0] as CLBeacon
closestBeacon=nearestBeacon
} else {
// message = "No beacons are nearby"
}
NSLog("%@", message)
sendLocalNotificationWithMessage(message)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.