[英]iPhone4S strange behavior at Beacon detection
我正在开发包含ibeacon检测的应用程序。
但是,当设备在后台B后面接收信标A时,什么也没发生。
条件
1. iPhone4S(iPhone5一切正常)
2.应用程序在后台
3.在检测到另一个信标(与另一个信标区不同)之后。
有人能帮我吗? 任何建议,将不胜感激。
感谢您的回复。 进入信标A(第二个)的区域比进入信标B(第一个)的区域大约延迟30秒,而我等待了大约20秒的本地通知将由“信标A”触发。 (Beacon-A区域和Beacon-B区域部分重叠。我在重叠的区域中等待。)
这是一段代码。
- (void)startBeaconMonitoring
{
if ([CLLocationManager respondsToSelector:@selector(isMonitoringAvailableForClass:)] && [CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]] && !self.locationManager) {
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
_storeUUID = [[NSUUID alloc] initWithUUIDString:@"MY UUID HERE"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:_storeUUID major:CENSOR_TYPE_A identifier:@"MY ID1"];
region.notifyOnExit = YES;
region.notifyOnEntry = YES;
CLBeaconRegion *region2 = [[CLBeaconRegion alloc] initWithProximityUUID:_storeUUID major:CENSOR_TYPE_B identifier:@"MY ID2"];
region.notifyOnExit = YES;
region.notifyOnEntry = YES;
[self.locationManager startMonitoringForRegion:region];
[self.locationManager startMonitoringForRegion:region2];
}
}
# pragma CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager requestStateForRegion:region];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
if ([region isMemberOfClass:[CLBeaconRegion class]] && [CLLocationManager isRangingAvailable]) {
CLBeaconRegion *beacon = (CLBeaconRegion*)region;
[self.locationManager startRangingBeaconsInRegion:beacon];
}
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
switch (state) {
case CLRegionStateInside:
if ([region isMemberOfClass:[CLBeaconRegion class]] && [CLLocationManager isRangingAvailable]) {
CLBeaconRegion *beacon = (CLBeaconRegion*)region;
int major = [beacon.major intValue];
[self.locationManager startRangingBeaconsInRegion:beacon];
}
break;
case CLRegionStateOutside:
case CLRegionStateUnknown:
default:
break;
}
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
if ([region isMemberOfClass:[CLBeaconRegion class]] && [CLLocationManager isRangingAvailable]) {
[self.locationManager stopRangingBeaconsInRegion:(CLBeaconRegion *)region];
}
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case kCLAuthorizationStatusAuthorized:
if (_locationDisabled) {
_locationDisabled = NO;
self.locationManager = nil;
[self startBeaconMonitoring];
}
break;
case kCLAuthorizationStatusRestricted:
case kCLAuthorizationStatusNotDetermined:
break;
case kCLAuthorizationStatusDenied:
_locationDisabled = YES;
break;
default:
break;
}
}
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
if (beacons.count > 0 && !_regionExit) {
for (CLBeacon *beacon in beacons) {
if ([beacon.proximityUUID.UUIDString isEqualToString:_storeUUID.UUIDString]) {
NSString *censorType = [NSString stringWithFormat:@"%@", beacon.major];
if ([censorType intValue] == CENSOR_TYPE_A) {
// DO ACTION A
} else if ([censorType intValue] == CENSOR_TYPE_B) {
// DO ACTION B
}
}
}
}
}
看来iOS 8上的iPhone4s在检测背景中快速区域变化方面存在问题。 我的测试表明,如果您松开第一个区域超过1分钟并输入新区域,则立即检测到该区域。 但是,如果您在不到1分钟的时间内松开区域,iPhone 4s将无法识别它,您将不得不等待(大约15分钟)进行完整的蓝牙扫描才能注意到它。 我采取了变通方法,即在丢失第一个区域60秒后开始测距,如果我在60秒内输入下一个信标,测距将检测到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.