问题描述
我注册了自己的位置管理器来监视和定位一些信标:
[self.locationManager startMonitoringForRegion:region];
[self.locationManager startRangingBeaconsInRegion:region];
我的理解是,当找到一个或多个信标时,此委托方法称为:
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
打开我的信标时确实调用了此委托方法,但是信标数组为空。有没有任何理由为什么我的信标未在该阵列中列出?
下面是显示这种情况的屏幕截图:
其他注意事项:
- 我使用了传输我的信标信号。稍后,我将尝试使用真正的信标,但是MacBeacon在iOS 7中对我来说运行良好。
- 我尝试将测距延迟到得到
didEnterRegion为止:
或didDetermineState:
被调用,但这仍会导致相同的结果。 - 我已请求我的位置管理器:
[self.locationManager requestWhenInUseAuthorization];
。 - 我有一个非常相似的代码,可以在Xcode 5 / iOS中正常编译7 SDK。这是特定的Xcode 6 / iOS 8行为吗?
- 我在我的plist中添加了
NSLocationWhenInUseUsageDescription
键。
原来是因为在创建 CLBeaconRegion $时我没有使用唯一标识符c $ c>。
特别感谢帮助我解决了这个问题。 / p>
I registered my own location manager to monitor and range a few beacons:
[self.locationManager startMonitoringForRegion:region];
[self.locationManager startRangingBeaconsInRegion:region];
My understanding is, when one or more beacons is found this delegate method is called:
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
This delegate method is indeed called when I turned on my beacon, but the beacons array is empty. Is there any reason why my beacon is not listed in that array?
Here's a screenshot to illustrate this situation:
Other things to note:
- I used MacBeacon to transmit my beacon signal. I will try to use a real beacon later, but MacBeacon has been working fine for me in iOS 7.
- I tried delaying ranging until I get
didEnterRegion:
ordidDetermineState:
is called, but that still result in the same thing. - I have requested location permission from my location manager:
[self.locationManager requestWhenInUseAuthorization];
. - I have a very similar code working fine compiled in Xcode 5/iOS 7 SDK. Is this a specific Xcode 6/iOS 8 behaviour?
- I have added
NSLocationWhenInUseUsageDescription
key in my plist.
Turns out this is because I am not using unique identifier when creating CLBeaconRegion
.
Special thanks to nayoso for helping me solve this.
这篇关于didRangeBeacon调用时未找到任何信标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!