【发布时间】:2012-07-14 08:14:07
【问题描述】:
我有一个应用程序,它显示用户位置的地图并跟踪用户,直到应用程序移到后台。此时,位置管理器被告知停止更新位置,而是监视一个区域(最后一个已知位置周围 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];
}
【问题讨论】:
标签: iphone ios objective-c mapkit core-location