I'm developing an app with iBeacon support. Basically, I have a single view that updates its content according to the nearest beacon, and to scan beacons, I use no framework (just the CoreLocation from Apple), even though I use Estimote Beacons.
The problem is that my application doesn't detect the beacons instantaneously, I have to wait about 5 seconds in front of a beacon in order to get the content updated, while the Estimote app detects the beacons within 1-2 seconds. My Estimote beacons are configured to advertise every 960 ms.
How is that possible ? Can I set a time interval to scan for beacons ? How to improve my app to update the view faster ?
Here is the code I use to initialize the location manager and to update the view :
// ViewController.h =================
@property (strong, nonatomic) CLLocationManager *locationManager;
// ViewController.m =================
-(void)initBeaconMonitor {
NSUUID *estimoteUUID = [[NSUUID alloc] initWithUUIDString:estimoteBeaconUUID];
_region = [[CLBeaconRegion alloc] initWithProximityUUID:estimoteUUID major:estimoteBeaconMajor identifier:beaconRegionIdentifier];
self.locationManager = [[CLLocationManager alloc] init];
// For iOS 8
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager startMonitoringForRegion:_region];
[self.locationManager startRangingBeaconsInRegion:_region];
[self.locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:
(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
if(beacons.count > 0) {
CLBeacon *nearestBeacon = beacons.firstObject;
if(nearestBeacon == _lastBeacon) {
return;
}
_lastBeacon = [nearestBeacon copy];
switch(nearestBeacon.proximity) {
case CLProximityFar:
break;
case CLProximityNear:
[self updateViewWithBeacon:nearestBeacon];
break;
case CLProximityImmediate:
[self updateViewWithBeacon:nearestBeacon];
break;
case CLProximityUnknown:
return;
}
}
}