停止测距信标区域

问题描述 投票:0回答:2

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

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
2个回答
0
投票

CLLocationManager有一个名为rangedRegions的财产,这是目前所有地区的NSSet。所以如果你做的事情如下:

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

如果你想停止所有地区的测距。


0
投票

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

    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;

当您进入或离开信标区域时,这将通知您

如果您需要其他任何东西,请告诉我

© www.soinside.com 2019 - 2024. All rights reserved.