locationManager:didEnterRegion not called when a beacon is detected
Check if your methods are implemented in the following way.In viewDidLoad
, start moniotoring at the end
self.beaconRegion.notifyOnEntry=YES;self.beaconRegion.notifyOnExit=YES;self.beaconRegion.notifyEntryStateOnDisplay=YES;[self.locationManager startMonitoringForRegion:self.beaconRegion];
after monitoring start, request state for your defined region
- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{ [self.locationManager requestStateForRegion:self.beaconRegion];}
after state is determined, start ranging beacons
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{ if (state == CLRegionStateInside) { //Start Ranging [manager startRangingBeaconsInRegion:self.beaconRegion]; } else { //Stop Ranging here }}
and implement the following methods according to your needs...
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{ self.statusLbl.text=@"Entered region";}-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{ self.statusLbl.text=@"Exited region";}-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{ if(beacons.count>0) {}}
Hope this will solve your problem.
before starting coding in project , you must follow given setup guidlines -->1. in project info or info.plist --> Custom IOS Target Properties --> . add "Required background modes" . in this add two items --> ."App shares data using CoreBluetooth" ."App registers for location updates"2. in project Capability --> There is Background Modes . check "Loaction update" . check "Acts as a Bluetooth LE accessory" . check "uses bluetooth LE accessories"
(and do follow the instructions given by Mr. Davidgyoung. believe me, it will definitely work.)
You also need to be aware that you are monitoring a region - not a particular beacons.
So if you have 3 beacons which share the same proximityUUID
and your region is defined as only proximityUUID
(without major and minor values) you will get notified only in two situations:
No beacons from the region were in range and first beacon/beacons getsdiscovered (
didEnterRegion:
)One or more beacons from the region were in range and they all went out of sight for~30 seconds (
didExitRegion:
)