信标接近范围将接近响应更改为近 - 立即 - 远,即使 ios 设备保持在同一位置。
当我打开 View 时,接近响应为“接近”。我来回收到邻近响应,“近”-“立即”,然后“近”。它一次又一次地显示 View
我们如何解决这个问题。是否有任何事件处理程序。
谢谢。
最佳答案
接近度和准确度值似乎相当“嘈杂”。它还可能取决于您的环境。水(以及人)会吸收蓝牙使用的频率,因此人员移动会产生影响,但当两个设备放在我的 table 上时,我观察到 1.2m 到 1.9m 之间的变化。
我认为您将不得不处理应用程序中的噪音。一旦 View 打开,您应该保持它打开,直到信标“远”(或者您获得区域导出)一段时间。如果状态转换回接近或立即,则重置计时器。
您需要使用一些类似于以下的代码 -
-(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;
}
关于ios - 即使应用程序位于同一位置,信标的邻近范围也会来回变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627580/