didRangeBeacon called without any beacons found

荒凉一梦 提交于 2019-12-23 09:10:33

问题


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

回答1:


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

Special thanks to nayoso for helping me solve this.




回答2:


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>




回答3:


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:


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.



来源:https://stackoverflow.com/questions/26429089/didrangebeacon-called-without-any-beacons-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!