Moh*_*ine 5 objective-c core-location ios ibeacon estimote
我正在开发一个支持iBeacon的应用程序.基本上,我有一个视图,根据最近的信标更新其内容,并扫描信标,我没有使用框架(只是Apple的CoreLocation),即使我使用Estimote Beacons.
问题是我的应用程序没有立即检测到信标,我必须在信标前等待大约5秒才能更新内容,而Estimote应用程序会在1-2秒内检测到信标.我的Estimote信标被配置为每960毫秒做一次广告.
怎么可能?我可以设置扫描信标的时间间隔吗?如何改进我的应用程序以更快地更新视图?
这是我用来初始化位置管理器和更新视图的代码:
// ViewController.h =================
@property (strong, nonatomic) CLLocationManager *locationManager;
// ViewController.m =================
-(void)initBeaconMonitor {
NSUUID *estimoteUUID = [[NSUUID alloc] initWithUUIDString:estimoteBeaconUUID];
_region = [[CLBeaconRegion alloc] initWithProximityUUID:estimoteUUID major:estimoteBeaconMajor identifier:beaconRegionIdentifier];
self.locationManager = [[CLLocationManager alloc] init];
// For iOS 8
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager startMonitoringForRegion:_region];
[self.locationManager startRangingBeaconsInRegion:_region];
[self.locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:
(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
if(beacons.count > 0) {
CLBeacon *nearestBeacon = beacons.firstObject;
if(nearestBeacon == _lastBeacon) {
return;
}
_lastBeacon = [nearestBeacon copy];
switch(nearestBeacon.proximity) {
case CLProximityFar:
break;
case CLProximityNear:
[self updateViewWithBeacon:nearestBeacon];
break;
case CLProximityImmediate:
[self updateViewWithBeacon:nearestBeacon];
break;
case CLProximityUnknown:
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
dav*_*ung 12
您无法在iOS上更改信标扫描间隔. 当在前景中进行测距时,iOS将不断扫描信标,因此这不会导致延迟.
问题在于,一旦CoreLocation确定信标处于近/近接近并且信标根据信标阵列中的分类位置最近,app逻辑将仅更新UI .场的排序和值proximity都基于对CoreLocation信标(accuracy场)的距离估计,并且这基于移动设备和信标之间的信号强度的20秒运行平均值.这是20秒的运行平均值导致你提到的延迟,因为距离估计缓慢更新并且直到移动设备相对于所有信标在相同位置持续20秒才达到稳定状态.不幸的是,这20秒是固定的,不可配置.
为了更快地响应,您可以停止使用accuracy数组中信标的字段和排序顺序.一些替代方案:
改变你的逻辑根本不是基于距离,可能是基于时间和以前看过的信标.
切换到使用该rssi字段作为距离的代理.此字段的平均值仅为1秒,但请注意,如果由于无线电噪声引起的可变性,它会有很多.该字段的较小负值表示更接近的信标.如@heypiotr在他的回答中建议的那样增加信标传输频率将有助于提供更稳定的RSSI数字.
在较短的时间间隔(2-5秒)内手动计算自己的RSSI运行平均值,以便在距离估计和稳定性的快速更新之间进行更好的权衡.
您可以在此处详细了解iBeacon测距的工作原理:
http://developer.radiusnetworks.com/2014/12/04/fundamentals-of-beacon-ranging.html
小智 2
减少信标的广告间隔应该可以提高响应能力,但请记住,这是以牺牲电池寿命为代价的。300\xe2\x80\x93400 ms 左右的时间通常是前者和后者之间的一个很好的权衡。您可以使用Estimote 的 iOS 应用程序来配置您的信标。
\n\niOS 使用信标的广告数据包来估计到信标的距离,从而确定邻近区域(远/近/立即)。它通常需要收集至少几个数据包以确保估计或多或少是正确的。这就是为什么更高频率的广告应该有所帮助。
\n