我有 2 个应用程序(1 个是在后台注册和扫描 iBeacons,没有测距),另一个没有。除了第一个为 iBeacons 启用之外,这两个应用程序本质上相似。
// location manager config
+ (CLLocationManager *)sharedLocationManager {
static CLLocationManager *_locationManager;
@synchronized(self) {
if (_locationManager == nil) {
_locationManager = [[CLLocationManager alloc] init];
//_locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
_locationManager.pausesLocationUpdatesAutomatically = NO;
if ([_locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]){
_locationManager.allowsBackgroundLocationUpdates = YES;
}
}
}
return _locationManager;
}
- (void)startMonitoringItem:(Item *)item {
CLBeaconRegion *beaconRegion = [self beaconRegionWithItem:item];
CLLocationManager *locationManager = [LocationTracker sharedLocationManager];
[locationManager startMonitoringForRegion:beaconRegion];
}
- (void)stopMonitoringItem:(Item *)item {
CLBeaconRegion *beaconRegion = [self beaconRegionWithItem:item];
CLLocationManager *locationManager = [LocationTracker sharedLocationManager];
[locationManager stopMonitoringForRegion:beaconRegion];
}
我在第一个应用程序中注册了大约 100 个 iBeacons,并在 iPhone 6 和 iPhone 6 Plus 上运行了这两个应用程序,在这 100 个 iBeacons 附近运行相同的操作系统版本,都启用了蓝牙。
我只对进入和退出事件感兴趣,基本上只是在第一个应用程序中实现了这两个调用。我运行了大约 14 个小时的测试,只需将启用蓝牙的两部 iPhone 放在 iBeacons 附近即可。
当我在设置菜单中检查电池状态时,第一个应用程序消耗的电池最多比第二个应用程序多 1%(例如:第一个应用程序:25%,第二个应用程序:24%),这在两个设备上都是相同的。这是预期行为,因为应优化由 iOS 控制的蓝牙扫描算法以节省电池电量。
但是,在我客户的设备上,第一个应用程序消耗的电量是第二个应用程序的 5 倍(例如:第一个应用程序:10%,第二个应用程序:2%)。
当我检查他的蓝牙设置时,我意识到他的 iPhone 与大约 8 台其他设备配对。
所以我的问题是这个。与其他设备配对是否会在我的第一个应用程序上导致更大的电池消耗,即使它只是在扫描 iBeacons?如果是,有什么方法可以通过算法优化以忽略配对设备并仅扫描 iBeacons。
我已经广泛阅读了 iOS 文档并咨询了 stackoverflow,但到目前为止还没有找到令人满意的答案。
我将不胜感激任何建议!
更新:请看截图示例
在上面的屏幕截图中,第一个和第二个应用程序的电池使用百分比在我的设备上几乎相同。但是,在我客户的设备(与其他 8 台设备配对)上,过去 24 小时和过去 7 天,第一个应用程序的电池使用百分比通常是第二个应用程序的 5 倍(例如:10% 到 2%) . 这两个应用程序在他的设备上运行的时间大致相同。这不是第一次发生。