stopRangingBeaconsInRegion是否有可能停止监视区域的通知? [英] It is possible that stopRangingBeaconsInRegion stop notifications of a monitored region?

查看:91
本文介绍了stopRangingBeaconsInRegion是否有可能停止监视区域的通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CLLocationManager进行示例项目.

I'm doing a sample project working with CLLocationManager.

我打电话给startMonitoringForRegion.然后,我开始与其他设备一起模拟信标,并调用didEnterRegion.

I call startMonitoringForRegion. Then, I start to simulate a beacon with other device and didEnterRegion is called.

didEnterRegion中,我呼叫startRangingBeaconsInRegion并正常工作.

In the didEnterRegion, I call startRangingBeaconsInRegion and works fine.

然后,我暂停信标发射器,并调用didExitRegion.在didExitRegion中,我叫stopRangingBeaconsInRegion.

Then, I pause the beacon emitter and didExitRegion is called. In the didExitRegion I call stopRangingBeaconsInRegion.

如果我再次启动信标发射器,则不会调用didEnterRegion.

If I start again the beacon emitter, didEnterRegion is not called.

我在Apple文档中找到了这一点:

I found this in the Apple documentation:

stopRangingBeaconsInRegion: 停止发送指定信标区域的通知.

stopRangingBeaconsInRegion: Stops the delivery of notifications for the specified beacon region.

stopRangingBeaconsInRegion是否可能停止监视区域的通知?

It is possible that stopRangingBeaconsInRegion stop notifications of a monitored region?

在没有stopRangingBeaconsInRegion的情况下,我也尝试了同样的方法,并且工作正常.

I try the same without the stopRangingBeaconsInRegion and works fine.

谢谢

添加更多信息:

NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:@"77777777-1717-2727-7777-777777777777"];
NSString *identifier = @"MyBeaconRegion";
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:UUID identifier:identifier];
[_locationManager startMonitoringForRegion:region];

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"didEnterRegion");
    [_locationManager startRangingBeaconsInRegion:(CLBeaconRegion*)region];
    NSLog(@"StartRangingBeacons");
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"didExitRegion");
    [_locationManager stopRangingBeaconsInRegion:(CLBeaconRegion*)region];
    NSLog(@"StopRangingBeacons");

}

- (void)locationManager:manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    for (CLBeacon *beacon in beacons) {
        NSLog(@"Ranging Beacon: %@ and proximity: %f", beacon.proximityUUID.UUIDString, beacon.accuracy);
    }
}

还有一些日志:

2015-01-13 09:46:30.559 RegionMonitoring[188:5314] didEnterRegion
2015-01-13 09:46:30.561 RegionMonitoring[188:5314] StartRangingBeacons
2015-01-13 09:46:31.579 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.008799
2015-01-13 09:46:32.575 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.011362
2015-01-13 09:46:33.580 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.012814
2015-01-13 09:46:34.580 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.012909
2015-01-13 09:46:35.579 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.012915
2015-01-13 09:46:36.579 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.011501
2015-01-13 09:46:37.576 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.010177
2015-01-13 09:46:38.576 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.013618
2015-01-13 09:46:39.578 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 09:46:40.573 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 09:46:41.578 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 09:46:42.575 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 09:46:43.578 RegionMonitoring[188:5314] didExitRegion
2015-01-13 09:46:43.579 RegionMonitoring[188:5314] StopRangingBeacons
2015-01-13 09:46:43.581 RegionMonitoring[188:5314] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000

然后,我打开信标,什么也没发生.

Then, I turn on the beacon and nothing happens.

如果我尝试使用此代码:

If I try with this code:

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"didExitRegion");
    //[_locationManager stopRangingBeaconsInRegion:(CLBeaconRegion*)region];
    //NSLog(@"StopRangingBeacons");
}

工作正常:

2015-01-13 10:15:45.945 RegionMonitoring[364:11017] didEnterRegion
2015-01-13 10:15:45.947 RegionMonitoring[364:11017] StartRangingBeacons
2015-01-13 10:15:46.960 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:15:47.960 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:15:48.961 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:15:49.958 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:15:50.960 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:51.958 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:52.960 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:53.956 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:54.960 RegionMonitoring[364:11017] didExitRegion
2015-01-13 10:15:54.962 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:55.955 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:56.960 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:15:57.959 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:02.960 RegionMonitoring[364:11017] didEnterRegion
2015-01-13 10:16:02.962 RegionMonitoring[364:11017] StartRangingBeacons
2015-01-13 10:16:02.963 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:16:02.971 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:16:03.979 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.040842
2015-01-13 10:16:04.979 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.036694
2015-01-13 10:16:05.978 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: 0.036051
2015-01-13 10:16:06.977 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:07.977 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:08.974 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:09.977 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:10.973 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:11.977 RegionMonitoring[364:11017] didExitRegion
2015-01-13 10:16:11.978 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:12.974 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000
2015-01-13 10:16:13.977 RegionMonitoring[364:11017] Ranging Beacon: 77777777-1717-2727-7777-777777777777 and proximity: -1.000000

推荐答案

代码看起来正确.我怀疑发生的事情是您在停止测距之后只是看到新检测的延迟.如果您等待15分钟,您会看到第二个区域进入事件吗?

The code looks correct. I suspect what is happening is you are simply seeing a delay on a new detection after you stop ranging. If you wait 15 minutes do you see second region entry event?

由于它告诉OS进行恒定的蓝牙扫描以查找信标,因此,在前景中绝对可以加快信标检测的速度.测距会导致检测在几秒钟内发生.如果不在范围内,iOS将使用15分钟的扫描周期来查找信标,而iPhone 5+上的蓝牙硬件过滤器可能会加快信标的扫描速度.硬件过滤器不是100%可靠的,因此检测到的声音有时会延迟最多15分钟.

Ranging in the foreground absolutely speeds up beacon detections beacause it tells the OS to do as constant Bluetooth scan to look for beacons. Ranging causes detections to happen within a few seconds. If not ranging, iOS uses a 15 minute scan cycle to look for beacons, which may be accelerated by bluetooth hardware filters on iPhone 5+. The hardware filters are not 100% reliable so detections sonetimes are delayed up to 15 minutes anyway.

有关详细信息,请参见此处: http://developer.radiusnetworks .com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

See here for details: http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

这篇关于stopRangingBeaconsInRegion是否有可能停止监视区域的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆