0
votes

I'm developing a beacon app which has a tour mode option. So when the user taps the switch to turn on the tour, I'm creating beacon regions and using below code I'm listening for beacons

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:beacon.beaconID];
CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:[beacon.major integerValue] minor:[beacon.minor integerValue] identifier:beacon.identifier];

[self.locationManager startMonitoringForRegion:region];
region.notifyEntryStateOnDisplay = YES;      
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
[self.locationManager startRangingBeaconsInRegion:region];

Now to stop the ranging, I know I have to use

    [self.locationManager stopRangingBeaconsInRegion:region];

But how do I get the same CLBeaconRegion created for monitoring? Should I save the CLBeaconRegion in an array?

2

2 Answers

0
votes

CLLocationManager has a property called rangedRegions which is an NSSet of all regions being currently ranged. So if you do something like:

for (CLBeaconRegion *region in self.locationManager.rangedRegions) {
    [self.locationManager stopRangingBeaconsInRegion:region];
}

If you want to stop ranging all regions.

0
votes

Let me tell you how can we first range for all available beacons then how to monitor a particular beacon.

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:beacon.beaconID];

    CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:beacon.identifier];

    [self.locationManager startRangingBeaconsInRegion:region];

This will give you all available beacons in Range which matches with uuid.

Then you need to start monitoring for a particular beacon.(say beacon)

     CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:beacon.uuid major:[beacon.major integerValue] minor:[beacon.minor integerValue] identifier:beacon.identifier];

     [self.locationManager startMonitoringForRegion:region];

     region.notifyEntryStateOnDisplay = YES;      
     region.notifyOnEntry = YES;
     region.notifyOnExit = YES;

This will notify you when you comes in or goes out from beacon region

Let me know if anything else you need