首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >信标检测中的iPhone4S奇怪行为

信标检测中的iPhone4S奇怪行为
EN

Stack Overflow用户
提问于 2014-06-16 15:39:19
回答 1查看 154关注 0票数 0

我正在开发包含ibeacon检测的应用程序。

但是,当设备在后台接收到B之后的信标A时,什么也没有发生。

条件

  1. iPhone4S(iPhone5正常) background
  2. After检测到另一个信标(与其他信标不同)的
  3. 应用。

有人能帮我吗?任何建议都将不胜感激。

感谢您的回复。进入信标A的区域(第二个)比进入信标B的区域(第一个)延迟了大约30秒,我等待了大约20秒,等待“信标A”将发射的LocalNotification。(Beacon-A区域和Beacon-B区域部分重叠。我在重叠的区域等待。)

这是一段代码。

代码语言:javascript
复制
- (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
                }
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-03-06 16:39:53

看起来iOS 8上的iPhone4s在检测后台的快速区域变化时有问题。我的测试表明,如果你松开第一个区域超过1分钟,并进入新的区域,它会立即被检测到。但是如果你松开区域不到1分钟,iPhone 4s将无法识别它,你将不得不等待(大约15分钟),直到完全蓝牙扫描才能注意到它。我做了一个解决办法,我在失去第一个区域60秒后开始测距,如果我将在60秒内进入下一个信标,测距将检测到它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24238723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档