didRangeBeacon called without any beacons found

2019-06-18 14:57发布

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:

enter image description here


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: or didDetermineState: 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.

4条回答
淡お忘
2楼-- · 2019-06-18 15:30

Turns out this is because I am not using unique identifier when creating CLBeaconRegion.

Special thanks to nayoso for helping me solve this.

查看更多
Evening l夕情丶
3楼-- · 2019-06-18 15:31

you have to first start beacon monitoring also set notifyEntryStateOnDisplay = YES

self.region1.notifyEntryStateOnDisplay = YES;
[theLocManager startMonitoringForRegion: region1];
[theLocManager startRangingBeaconsInRegion: region1];

That code works just fine for me also in iOS 8.

查看更多
淡お忘
4楼-- · 2019-06-18 15:45

Try using the Locate app on your iOS 8 device, and verify you see the beacon. Make sure you have the UUID of the beacon configured into the Locate app properly.

If you do see it on Locate, then I suspect the issue is that permissions are not properly granted to your app on iOS 8. In this case, you should probably post a code snippet showing your setup where you call [self.locationManager requestWhenInUseAuthorization]; and also include a section of your plist file which needs to have something like:

<key>NSLocationWhenInUseUsageDescription</key> <string>Need to use location services</string>

查看更多
再贱就再见
5楼-- · 2019-06-18 15:51

I actually had this problem when I created my CLBeaconRegion with a major and minor as arguments. If you create the beacon region with major and minor arguments and don't have any beacons with those major and minors the beacon list will be empty. In my case, I wanted to dynamically determine the major/minor. Once I init the CLBeaconRegion with just the UUID and Identifier all was well.

查看更多
登录 后发表回答