Proximity range for Beacons changes back and forth even when the App is in the same place

喜你入骨 提交于 2019-12-04 15:53:38

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;
}
davidgyoung

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!