In Stack Overflow, I've seen answer to find closest beacon (Swift find closest Beacon by rssi).
Here I tried with accuracy to find closest in Objective-C. My app finds beacon in every sec that time accuracy is not working finding closest properly. As he said RSSI will update in every 1 sec. So I'd like to filter closest beacon using RSSI. I converted your Swift code into Objective-C but it's not working fine.
Here is Swift code:
//Swift code
var closestBeacon: CLBeacon? = nil
for beacon in beacons {
if beacon.rssi < 0 && closestBeacon != nil && beacon.rssi > closestBeacon!.rssi {
closestBeacon = beacon as? CLBeacon
}
}
Here is Objective-C code I converted not working:
CLBeacon *closest = nil;
for (CLBeacon *beacon in beacons) {
if (beacon.rssi < 0 && closest != nil && beacon.rssi > closest.rssi) {
closest = beacon;
}
}
Here please make me perfect where I'm doing wrong.
There is a bug in both versions of code as @paulw11 suggests. Since I wrote that bug in response to another question here is a fix:
Swift
Objective-C
I fixed the bug in the original post, too.