質問

I'm trying to make applications, which ranges CLBeaconRegion.

I watched video from WWDC and presenter said, that I should call startMonitoringForRegion and, then user is inside region, startRangingBeaconsInRegion. I tried.

if (!_locationManager) {
    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}

CLBeaconRegion *targetRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:UUIDString] identifier:identifier];
targetRegion.notifyEntryStateOnDisplay = YES;
targetRegion.notifyOnEntry = YES;
targetRegion.notifyOnExit = YES;

[_locationManager startMonitoringForRegion:targetRegion];
[_locationManager startUpdatingLocation];

But it's not sending nothing to delegate. Beacons is working.

If I call just

[_locationManager startRangingBeaconsInRegion:region];

Applications finds all my beacons around me.

Should I just call second method or I'm incorrect?

Have you any suggestions?

役に立ちましたか?

解決

The most likely explanation is that you are not waiting long enough to get a call to your delegate. When you are NOT ranging, it takes up to 15 minutes to get callbacks to the delegate methods below. When you are ranging, it takes only 1 second.

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state 
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

If you wait the 15 minutes, I suspect you will get the callbacks as expected. The reason it is so much faster when you are ranging is because iOS does constant bluetooth scans when ranging is enabled to look for iBeacons. When you are not ranging, it slows down these scans to save battery. See more info in the blog posts below:

http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

http://developer.radiusnetworks.com/2014/03/12/ios7-1-background-detection-times.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top