简体   繁体   English

iPhone4S在信标检测时出现异常行为

[英]iPhone4S strange behavior at Beacon detection

I'm developing app that includes ibeacon detection. 我正在开发包含ibeacon检测的应用程序。
But, when device receiving beacon A after B in background, nothing happened. 但是,当设备在后台B后面接收信标A时,什么也没发生。

Condition 条件
1. iPhone4S(iPhone5 is all ok) 1. iPhone4S(iPhone5一切正常)
2. App is in background 2.应用程序在后台
3. After detection of another beacon(different BeaconRegion from another one). 3.在检测到另一个信标(与另一个信标区不同)之后。

Can someone help me? 有人能帮我吗? Any suggestion would be appreciated. 任何建议,将不胜感激。

Thank you for replying. 感谢您的回复。 Entering the area of Beacon A(second one) is delayed about 30 seconds from Entering the area of Beacon B(first one), and I waited about 20 seconds for LocalNotification that will be fired by "Beacon A". 进入信标A(第二个)的区域比进入信标B(第一个)的区域大约延迟30秒,而我等待了大约20秒的本地通知将由“信标A”触发。 (Beacon-A area and Beacon-B area overlap each other partially. And I waited in the overlapped area.) (Beacon-A区域和Beacon-B区域部分重叠。我在重叠的区域中等待。)

This is piece of code. 这是一段代码。

- (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
                }
            }
        }
    }
}

It looks that iPhone4s on iOS 8 has problem with detecting quick region change in background. 看来iOS 8上的iPhone4s在检测背景中快速区域变化方面存在问题。 My test showed that if you loose first region for more than 1 min and enter new region than it is detected immediately. 我的测试表明,如果您松开第一个区域超过1分钟并输入新区域,则立即检测到该区域。 But if you loose region for less than 1 min iPhone 4s won't recognise it and you will have to wait (around 15 min) for full bluetooth scan to notice it. 但是,如果您在不到1分钟的时间内松开区域,iPhone 4s将无法识别它,您将不得不等待(大约15分钟)进行完整的蓝牙扫描才能注意到它。 I made workaround that I start ranging after losing first region for 60 seconds, if I will enter next beacon in 60 seconds ranging will detect it. 我采取了变通方法,即在丢失第一个区域60秒后开始测距,如果我在60秒内输入下一个信标,测距将检测到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM