iOS 10中的测距信标

t_m*_*_ms 8 bluetooth objective-c core-location ios ios10

在我的应用程序中,我在CoreLocation中使用Beacon Region Monitoring.该应用将2个proximityUUID设置为区域(它们具有不同的ID),并开始如下所示的范围.

#pragma mark - CLLocationManagerDelegate

(void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region {
     [self.locationManager requestStateForRegion:(CLBeaconRegion *)region];
}

- (void)locationManager:(CLLocationManager *)manager 
didExitRegion:(CLRegion *)region {
     [self.locationManager stopRangingBeaconsInRegion:(CLBeaconRegion *)region]; 
}

- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{ 
    for(CLBeacon* b in beacons){
         //output only previous beacon if it's before regionout to previous region
         NSLog(@"%@",b);
    }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
     //error
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{ 
   if(state == CLRegionStateInside){
        if ([region isMemberOfClass:[CLBeaconRegion class]] && [CLLocationManager isRangingAvailable]){
            [self.locationManager startRangingBeaconsInRegion:(CLBeaconRegion *)region];
        }
  }
}
Run Code Online (Sandbox Code Playgroud)

它适用于iOS 8和iOS 9,但在iOS 10中不起作用.

[在iOS 8/iOS 9中]

1.broadcast beacon1

2.[app]didRangeBeacons (beacon1)

3.stop beacon1 and broadcast beacon2

4.[app]didRangeBeacons (beacon2)
Run Code Online (Sandbox Code Playgroud)

[iOS 10]

1.broadcast beacon1

2.[app]didRangeBeacons (beacon1)

3.stop beacon1 and broadcast beacon2

4.[app]didRangeBeacons (**beacon1**)
Run Code Online (Sandbox Code Playgroud)

这是iOS 10的错误吗?

小智 0

好的,我在 Swift 3 中遇到了同样的问题,但我解决了。

似乎有两件事(可能直接相关):

  • 对于 iOS10,信标的广告间隔可能设置得太高(将其设置为大约 200 毫秒,然后按照 Macrumors 上 dantastic 的建议,它应该在 9 和 10 上工作)

  • 我如何让它再次工作:我在装有 iOS 9.3.5 的 iPad 上测试了它,需要将部署目标更改为 9.3。这表明它在我的 iOS 9 的 iPad 上再次工作,但是......在我的 iOS 10 设备上也解决了这个问题。