【问题标题】:didrangebeacons not called even though didDetermineState is called即使调用了 didDetermineState,也没有调用 didrangebeacons
【发布时间】:2015-04-29 07:21:25
【问题描述】:

我有一组 Estimote 信标。当我使用 estimote sdk 时,我可以为信标设置范围并使用它。但问题是,当我使用iOS SDK进行监控测距时,根本没有调用didRangeBeacons。

我已经开始测距,如下所示。当我使用断点检查时,该函数被调用。

- (void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    switch (state) {
        case CLRegionStateInside:
            [self.beaconManager startRangingBeaconsInRegion:self.beaconRegion];
            NSLog(@"Region CLRegionStateInside");

【问题讨论】:

    标签: ios core-location ibeacon estimote


    【解决方案1】:

    请确保您已完成以下清单:

    1. 您已在 info.plist 中输入 NSLocationAlwaysUsageDescription

    2. 您的属性 self.beaconRegion 是一个 CLBeacon 区域,其 UUID 与您要检测的 UUID 匹配。

    3. 您的设备是 iPhone 4S 或更新版本,运行 iOS 7 或更高版本,并且开启了蓝牙

    我会将代码更改为如下所示:

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(nonnull CLRegion *)region {
        CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
                if (beaconRegion.major && beaconRegion.minor) {
                } else {
                    switch (state) {
                        case CLRegionStateUnknown:
                            // Handle this case when bluetooth is off.
                            break;
                        case CLRegionStateInside:
                            NSLog(@"Inside %@", region);
                            if (![self.locationManager.rangedRegions containsObject:beaconRegion]) {
                                [self.locationManager startRangingBeaconsInRegion:[[CLBeaconRegion alloc] initWithProximityUUID:beaconRegion.proximityUUID identifier:beaconRegion.proximityUUID.UUIDString]];
                            }
                            break;
                    case CLRegionStateOutside:
                        NSLog(@"Outside %@", region);
                        break;
                }
            }
        }
    

    您只需要在 UUID 上进行范围,因为这将拾取与该 UUID 匹配的所有信标,而不管主要和次要。另请注意,如果您尚未进行测距,则应仅尝试开始测距以避免额外的函数调用

    【讨论】:

      猜你喜欢
      • 2017-07-06
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多