-->

Proximity range for Beacons changes back and forth

2020-07-24 20:48发布

问题:

Beacon Proximity range changes the proximity response as Near - Immediate - Far, even while the ios Device remains in the same place.

As I open a view when the proximity response is Near. I get the proximity response back and forth, Near - immediate then Near. It shows up the view again and again

How can we solve this issue. Is there any event handler.

Thanks.

回答1:

The proximity and accuracy values appear to be quite 'noisy'. It can also depend on your environment. Water (and therefore people) absorbs the frequencies used by Bluetooth so people moving can have an impact, but I observe variation in between 1.2m and 1.9m when both devices are sitting on my desk.

I think you are going to have to deal with the noise in your app. Once a view has opened you should keep it open until the beacon is 'far' (or you get a region exit) for some period of time. If the state transitions back to near or immediate then reset the timer.

You need to use some code similar to the following -

-(void)locationManager:(CLLocationManager *)manager
    didRangeBeacons:(NSArray *)beacons
           inRegion:(CLBeaconRegion *)region {

    CLBeacon *beacon=beacons[0];

    switch (beacon.proximity) {

    case CLProximityFar:
        if (self.farTimer==nil) {
            self.farTimer=[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(farTimerFired:) userInfo:beacon repeats:NO];
        }
    break;

    case CLProximityNear:
    case CLProximityImmediate:
        if (self.farTimer!=nil) {
            [self.farTimer invalidate];
            self.farTimer=nil;
        }
    break;

    case CLProximityUnknown:
         NSLog(@"Beacon proximity is unknown");
    break;
   }
}

-(void) farTimerFired:(NSTimer *)timer {
 CLBeacon *beacon=(CLBeacon *)timer.userInfo;
 NSLog(@"Beacon %@ is really far",beacon.proximityUUID.UUIDString);
 self.farTimer=nil;
}


回答2:

Understand that the proximity value is just an estimate based on radio signal strength, so this is expected behavior due to noise as @Paulw11 says in his answer.

Two things you can do to make the proximity (and accuracy) readings as solid as possible:

  1. Choose an iBeacon with as fast of a transmission rate as possible. Different ibeacons transmit advertisements at different frequencies from 30 times per second to once per second or less. Generally, faster transmission rates give you less noisy distance estimates because they give iOS more radio signal strength measurements to work with. For your testing, Try an iOS-based iBeacon like Locate for iBeacon to see if it helps. It is known to transmit 30x per second.

  2. Make sure your iBeacon is properly calibrated. This will not reduce the noise, but it will make sure the readings you get are correct as possible on average. If not properly calibrated you may see jumps between immediate and near more often when the device is solidly in the immediate zone, because it is calculating the distance as too far away.

Beyond this, A software filter on the proximity value might help as @Paulw11 suggests, but it still won't be perfect. You simply have to decide if you can live with the noise for your use case.