Supposing my code looks like this:
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region {
//Handle beacons found during ranging
}
-(void)initBeaconRegion
{
NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID major:345 minor:678 identifier:@"MyBeaconIdentifier"];
self.beaconRegion.notifyEntryStateOnDisplay = NO; //Used for Monitoring
self.beaconRegion.notifyOnEntry = YES; //Used for Monitoring
self.beaconRegion.notifyOnExit = YES; //Used for Monitoring
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
if ([region isKindOfClass:[CLBeaconRegion class]]) {
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
//now start ranging
// [_locationManager startRangingBeaconsInRegion:beaconRegion];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
[self initBeaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
NSLog(@"monitored regions %@",self.locationManager.monitoredRegions);
}
and some iPad app called xBeacon advertising with the same UUID, major and minor, this doesn't work. What am I doing wrong? Should I approach the advertising device with the app, or wait longer?
Tried the same with Estimote beacon app, and both apps work as I check it on Beacon Scanner on my Mac.
You are expecting a beacon monitoring callback to get called, but you aren't starting monitoring -- you are starting ranging. Try changing this line:
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
to:
[self.locationManager startMonitoringRegion:self.beaconRegion];
Also, you need to set self.locationManager.delegate = self
as @luca-corti suggests.
If you still don't get the callback, try using my Locate app to verify your test beacon is actually transmitting with the identifiers you expect.