1

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.

mad_mask
  • 776
  • 2
  • 10
  • 31
  • Solution can be found here. http://stackoverflow.com/questions/22627580/proximity-range-for-beacons-changes-back-and-forth-even-when-the-app-is-in-the-s/22628608?noredirect=1#comment45017403_22628608 Thanks to Paulw11. – mad_mask Feb 05 '15 at 13:25

1 Answers1

1

In one of my Past work, there was the need of same thing. I hope one of following will help you.In my case my Logic was based on RSSI( it is also fluctuating frequently )

Way 1 Place a counter for CLProximityFar and CLProximityNear, and based on that trigger action, Calculate the number of consecutive occurence of same Proximity, if is it so then consider that PROximity and trigger its action.

Way 2 This is completely based on RSSI value. For this you need to use 10-20 continuous RSSI values, take their Average and on the basis of that Trigger the action.

Mrug
  • 4,963
  • 2
  • 31
  • 53
  • Thank you for the answer, can you share an example of this please ? Right now i use Paulw11 solution with a timer. When it detect far, i start a timer and i check if i m really far, if i m really far i change the view on device. – mad_mask Mar 29 '15 at 17:04