我有一个应用程序,显示用户的位置地图,并跟踪用户,直到应用程序被移到后台。此时,位置管理器被告知停止更新位置,而是监视一个区域(距离最后一个已知位置的半径为100米)。在iOS模拟器上,它按预期工作,并显示地理位置指示符(与常规位置服务指示符相同,但只显示大纲)。在iPhone上,它似乎像预期的那样工作,但显示的是常规位置服务图标,而不是仅显示大纲。
有什么可能会发生这种情况,模拟器和手机之间的差异吗?我只是想确保手机真的只使用地理功能而不使用其他服务(即确保最小的电池使用量)。
其他信息:
我需要设置后台模式来接收位置更新--这是在特定情况下(当用户启用它时),而不是所有时间。不过,我试过禁用它,但问题仍然存在。
我用在后台的程序代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Only monitor significant changes – unless specified
if(!self.viewController.userSpecifiedToUseLocationServices)
{
// Stop using full location services
[self.viewController.locationManager stopUpdatingLocation];
// Create a boundary -- a circle around the current location
self.viewController.currentBoundary = [[CLRegion alloc] initCircularRegionWithCenter:self.viewController.locationManager.location.coordinate radius:kSignificantLocationChange identifier:@"Current Location Boundary"];
// Monitor the boundary
[self.viewController.locationManager startMonitoringForRegion:self.viewController.currentBoundary desiredAccuracy:kCLLocationAccuracyBest];
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Stop monitoring the region
if(self.viewController.currentBoundary != nil)
{
[self.viewController.locationManager stopMonitoringForRegion:self.viewController.currentBoundary];
self.viewController.currentBoundary = nil;
}
// Start full location services again
[self.viewController.locationManager startUpdatingLocation];
}发布于 2012-07-15 07:07:36
首先,模拟器上的位置服务从来都不是真实设备的高保真表示。因此,我不一定认为您会在两个测试平台上看到相同的情况。
其次,根据this answer on stack overflow的说法,这似乎是iOS 5上的正常行为(显示不同的指标)。
我还要提醒大家,地理击剑并不是一种神奇的技术。该设备仍需使用定位服务,这将耗尽电池。我当然建议使用苹果的startMonitoringForRegion:或startMonitoringForRegion:desiredAccuracy:,并利用它们的实现,而不是自己编写代码。但是,我也不会期望电池损耗可以忽略不计。
最后,您将精度指定为kCLLocationAccuracyBest,而不是使用startMonitoringForRegion:,或者指定较低的精度要求。我不明白这将如何影响,而不是电池的性能。更高的精确度意味着操作系统要么得到更高质量的补丁,要么定期投票,或者两者兼而有之。
遗憾的是,没有免费午餐:
https://stackoverflow.com/questions/11482146
复制相似问题