stopRangingBeaconsInRegion 有可能停止受监控区域的通知吗?
It is possible that stopRangingBeaconsInRegion stop notifications of a monitored region?
我正在做一个使用 CLLocationManager
的示例项目。
我叫startMonitoringForRegion
。然后,我开始用其他设备模拟信标并调用 didEnterRegion
。
在 didEnterRegion
中,我调用 startRangingBeaconsInRegion
并且工作正常。
然后,我暂停信标发射器并调用 didExitRegion
。在 didExitRegion
我调用 stopRangingBeaconsInRegion
.
如果我再次启动信标发射器,didEnterRegion
不会被调用。
我在 Apple 文档中找到了这个:
stopRangingBeaconsInRegion:
Stops the delivery of notifications for the specified beacon region.
有没有可能stopRangingBeaconsInRegion
停止某个监控区域的通知?
我在没有 stopRangingBeaconsInRegion
的情况下尝试了同样的方法并且工作正常。
谢谢
添加更多信息:
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
然后,我打开信标,但没有任何反应。
如果我尝试使用此代码:
- (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
根据 startMonitoringForRegion is not calling didEnterRegion if the app is started within the region,“didEnterRegion
是一个阈值事件,在进入某个区域时触发。想一想:表示您在某个区域内的事件会连续触发。”它没有触发的原因可能是因为当您调用 startRangingBeaconsInRegion
时您已经在该区域中,因此 didEnterRegion
不会被调用。
代码看起来正确。我怀疑正在发生的事情是您只是在停止测距后看到新检测的延迟。如果您等待 15 分钟,您会看到第二次区域进入事件吗?
在前台测距绝对会加快信标检测速度,因为它告诉 OS 像持续扫描蓝牙一样寻找信标。测距导致检测在几秒钟内发生。如果没有测距,iOS 使用 15 分钟的扫描周期来寻找信标,这可能会被 iPhone 5+ 上的蓝牙硬件过滤器加速。硬件过滤器并非 100% 可靠,因此检测有时会延迟最多 15 分钟。
我正在做一个使用 CLLocationManager
的示例项目。
我叫startMonitoringForRegion
。然后,我开始用其他设备模拟信标并调用 didEnterRegion
。
在 didEnterRegion
中,我调用 startRangingBeaconsInRegion
并且工作正常。
然后,我暂停信标发射器并调用 didExitRegion
。在 didExitRegion
我调用 stopRangingBeaconsInRegion
.
如果我再次启动信标发射器,didEnterRegion
不会被调用。
我在 Apple 文档中找到了这个:
stopRangingBeaconsInRegion: Stops the delivery of notifications for the specified beacon region.
有没有可能stopRangingBeaconsInRegion
停止某个监控区域的通知?
我在没有 stopRangingBeaconsInRegion
的情况下尝试了同样的方法并且工作正常。
谢谢
添加更多信息:
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
然后,我打开信标,但没有任何反应。
如果我尝试使用此代码:
- (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
根据 startMonitoringForRegion is not calling didEnterRegion if the app is started within the region,“didEnterRegion
是一个阈值事件,在进入某个区域时触发。想一想:表示您在某个区域内的事件会连续触发。”它没有触发的原因可能是因为当您调用 startRangingBeaconsInRegion
时您已经在该区域中,因此 didEnterRegion
不会被调用。
代码看起来正确。我怀疑正在发生的事情是您只是在停止测距后看到新检测的延迟。如果您等待 15 分钟,您会看到第二次区域进入事件吗?
在前台测距绝对会加快信标检测速度,因为它告诉 OS 像持续扫描蓝牙一样寻找信标。测距导致检测在几秒钟内发生。如果没有测距,iOS 使用 15 分钟的扫描周期来寻找信标,这可能会被 iPhone 5+ 上的蓝牙硬件过滤器加速。硬件过滤器并非 100% 可靠,因此检测有时会延迟最多 15 分钟。