簡體   English   中英

iPhone4S在信標檢測時出現異常行為

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM