如何停止iBeacon扫描

时间:2017-05-10 06:18:00

标签: ios objective-c xcode ibeacon

我试过这个代码,但这个代表没有打电话而不是停止扫描,在一个特殊情况下我需要调用其他功能。

-(void)locationManager:(CLLocationManager *)manager stopRangingBeaconsInRegion:(CLBeaconRegion *)region

{
NSLog(@"STOP PLEASEEEEEEEE");

}


- (void)locationManager:(CLLocationManager *)manager stopMonitoringForRegion:(CLRegion *)region {

NSLog(@"didExitRegion");
[manager stopRangingBeaconsInRegion:(CLBeaconRegion*)region];
NSLog(@"StopRangingBeacons");

}

我正在使用此代码启动beaconScanning

-(void)loadUIElements
{

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND , 0), ^{
    self.beaconRegionAny = [[AIBBeaconRegionAny alloc] initWithIdentifier:@"Any"];
    [self.locationManager requestWhenInUseAuthorization];
    self.locationManager.pausesLocationUpdatesAutomatically = YES;
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegionAny];    });

}

在开始监控信标时调用此函数

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region

{

1 个答案:

答案 0 :(得分:0)

您必须使用monitoredRegionsstopMonitoring(for:)列表中删除侦听器。这是指documentation

的链接

你试过这个吗?

[self.locationManager stopMonitoringForRegion:self.beaconRegionAny];