First of all:
Replace your long else/if
of locationManager:didRangeBeacons:inRegion:
with:
if (([closestBeacon.minor intValue] > 0 && [closestBeacon.minor intValue] <= 11) || [closestBeacon.minor intValue] == 30)
{
actualSection = [closestBeacon.minor intValue];
[self immediateDetection];
}
Replace your long else/if
in immediateDetection
with:
if ((actualSection > 0 && actualSection < 10 || actualSection == 30)
{
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = actualSection;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}
else if (actualSection == 10 || actualSection == 11)
{
ThiefAlarmViewController *thiefAlarmView = [[ThiefAlarmViewController alloc] init];
[self presentViewController:thiefAlarmView animated:NO completion:nil];
}
else
{
}
That should save you a lot of code.
For your issue, you could to this:
NSPredicate *predicateIrrelevantBeacons = [NSPredicate predicateWithFormat:@"(self.accuracy != -1) AND ((self.proximity != %d) OR (self.proximity != %d))", CLProximityFar,CLProximityUnknown];
NSArray *relevantsBeacons = [beacons filteredArrayUsingPredicate: predicateIrrelevantBeacons];
NSPredicate *predicateMin = [NSPredicate predicateWithFormat:@"self.accuracy == %@.@min.accuracy", relevantsBeacons];
CLBeacon *closestBeacon = nil;
NSArray *closestArray = [[relevantsBeacons filteredArrayUsingPredicate:predicateMin];
if ([closestArray count] > 0)
closestBeacon = [closestArray objectAtIndex:0];
if (closestBeacon)
{ //Do your thing }
else
{//No relevant close beacon}