【问题标题】:stop ranging beacon region停止测距信标区域
【发布时间】:2014-10-08 13:43:37
【问题描述】:

我正在开发一个具有游览模式选项的信标应用程序。因此,当用户点击开关打开游览时,我正在创建信标区域并使用以下代码监听信标

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:beacon.beaconID];
CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:[beacon.major integerValue] minor:[beacon.minor integerValue] identifier:beacon.identifier];

[self.locationManager startMonitoringForRegion:region];
region.notifyEntryStateOnDisplay = YES;      
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
[self.locationManager startRangingBeaconsInRegion:region];

现在要停止测距,我知道我必须使用

    [self.locationManager stopRangingBeaconsInRegion:region];

但是如何获得相同的 CLBeaconRegion 创建用于监控?我应该将 CLBeaconRegion 保存在数组中吗?

【问题讨论】:

    标签: ios8 core-location ibeacon


    【解决方案1】:

    CLLocationManager 有一个名为rangedRegions 的属性,它是当前范围内所有区域的NSSet。因此,如果您执行以下操作:

    for (CLBeaconRegion *region in self.locationManager.rangedRegions) {
        [self.locationManager stopRangingBeaconsInRegion:region];
    }
    

    如果您想停止对所有区域进行测距。

    【讨论】:

      【解决方案2】:

      让我告诉你我们如何首先确定所有可用信标的范围,然后如何监控特定的信标。

          NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:beacon.beaconID];
      
          CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:beacon.identifier];
      
          [self.locationManager startRangingBeaconsInRegion:region];
      

      这将为您提供 Range 中与 uuid 匹配的所有可用信标。

      然后你需要开始监控特定的信标。(比如信标)

           CLBeaconRegion *region  = [[CLBeaconRegion alloc] initWithProximityUUID:beacon.uuid major:[beacon.major integerValue] minor:[beacon.minor integerValue] identifier:beacon.identifier];
      
           [self.locationManager startMonitoringForRegion:region];
      
           region.notifyEntryStateOnDisplay = YES;      
           region.notifyOnEntry = YES;
           region.notifyOnExit = YES;
      

      当您从信标区域进出时,这会通知您

      如果你还需要什么,请告诉我

      【讨论】:

        猜你喜欢
        • 2017-01-03
        • 1970-01-01
        • 2018-10-12
        • 2014-02-11
        • 2022-06-11
        • 1970-01-01
        • 2014-08-30
        • 2017-01-13
        • 2019-08-24
        相关资源
        最近更新 更多