简体   繁体   English

CLLocationManager +监视CLBeaconRegion

[英]CLLocationManager + monitoring for CLBeaconRegion

I'm trying to make applications, which ranges CLBeaconRegion. 我正在尝试制作范围为CLBeaconRegion的应用程序。

I watched video from WWDC and presenter said, that I should call startMonitoringForRegion and, then user is inside region, startRangingBeaconsInRegion. 我看了来自WWDC的视频,演示者说,我应该调用startMonitoringForRegion,然后用户在区域内,即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. 当您不在范围内时,最多需要15分钟才能获得以下委托方法的回调。 When you are ranging, it takes only 1 second. 进行测距时仅需1秒钟。

- (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. 如果您等待15分钟,我怀疑您会按预期获得回调。 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. 进行测距时速度如此之快的原因是,当启用测距功能以查找iBeacons时,iOS会进行持续的蓝牙扫描。 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/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM