I want to insert a timer to avoid the change back between "far","near","immediate" state.
i use same view for "far" and "near" state but i push a new view for immediate state.
So for the immediate case for the return to root, i have find a solution by doing this :
[self performSelector:@selector(patchSelectorPopToRoot) withObject:nil afterDelay:4];
How can i do for the "near" and "far" state if i use same view ?
This is the delegate :
-(void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region
{
// Descriptor on distance to sort the array of beacons by distance
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
// Sorting the array of beacons
// Beacon array is sorted based on distance
// Closest beacon is the first one
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
if([self.beaconsArray count] > 0)
{
if(!self.selectedBeacon)
{
// initialy pick closest beacon
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}
else
{
//Sorting the array of beacons
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
//Updating the selected beacon with the first element of the array (closest beacon)
if(self.selectedBeacon != [beacons objectAtIndex:0] )
{
self.selectedBeacon = [beacons objectAtIndex:0];
currentBeaconMinor = self.selectedBeacon.minor;
}
}
// Switch on proximity of the closest beacon
switch (self.selectedBeacon.proximity)
{
case CLProximityUnknown:
{
[self DoOnProximityUnknow];
break;
}
case CLProximityImmediate:
{
[self DoOnProximityImmediate];
break;
}
case CLProximityNear:
{
[self DoOnProximityNear];
break;
}
case CLProximityFar:
{
[self DoOnProximityFar];
break;
}
default:
break;
}
self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
}
}
this is the method where i want to use the timer (Near).
-(void)DoOnProximityNear
{
//Starting a timer
//not working :
//[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
//not working
/*
double delayInSeconds = 20.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Do some work");
});*/
}
I just want a timer of 20 sec inside my "Near" method. i want to stay at least 20 seconds before going back on "Far".
Where should i insert this timer ? Should i wait for a far signal, start the timer and wait to an another far signal or should i start the timer when i arrive on near ?
Please how can i fix this issue ?
Thanks in advance for your help.