How to know the closest iBeacon

后端 未结 3 1625
無奈伤痛
無奈伤痛 2021-01-06 07:22

I have a code to know which beacon is the closest, but I have a problem when a beacon\'s accuracy is -1.00000, the the app takes the second one.

So there is a bucle

3条回答
  •  执念已碎
    2021-01-06 08:19

    locationManager:didRangeBeacons:inRegion: will return you a list of beacons in proximity order. That is, the first beacon in the list will be the nearest to you.

    However, there is one exception to this rule: if any beacons have a proximity of Unknown, then they will be at the top of the list (because their accuracy is -1). To account for this, simply filter out any Unknown beacons, and then pick the first in the list:

    beacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"proximity != %d", CLProximityUnknown]];
    CLBeacon *nearestBeacon = [beacons firstObject];
    

提交回复
热议问题