Luk*_*rey 4 iphone objective-c core-location mapkit ios
我有一个应用程序,显示用户位置的地图,并跟踪用户,直到应用程序移动到后台.此时,位置管理器被告知停止更新位置,而是监视一个区域(最后一个已知位置周围100米半径).在iOS模拟器上,它按预期工作并显示Geofencing指标(与常规位置服务指标相同,但仅限于大纲).在iPhone上,它似乎按预期工作,但显示常规位置服务图标而不是单独的轮廓.
是否有任何原因可能发生这种情况,模拟器和手机之间存在这种差异? 我只是想确保手机真的只使用Geofencing而没有其他服务(即确保最少的电池使用).
附加信息:
我已经要求将后台模式设置为接收位置更新 - 这是在特定情况下(当用户启用它时)而不是所有时间.不过,我已尝试禁用此功能,问题仍然存在.
我用来为应用程序添加背景的代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
嗯,首先,模拟器上的定位服务从未成为真实设备的高保真表示.所以,我不一定会认为你会在两个测试平台上看到同样的东西.
其次,根据这个关于堆栈溢出的答案,听起来这是iOS 5上的正常行为(显示不同的指标).
我还提醒说,地理围栏并不是一项神奇的技术.该设备仍然必须使用定位服务,这将耗尽电池.我当然会建议使用Apple startMonitoringForRegion:或者startMonitoringForRegion:desiredAccuracy:利用它们的实现,而不是编写自己的代码.但是,我也不希望电池消耗可以忽略不计.
最后,您将准确性指定为kCLLocationAccuracyBest,而不是使用 startMonitoringForRegion:或指定较低的准确度要求.我不知道为什么这不会影响电池性能.更高的准确性意味着操作系统必须要么获得更高质量的修复,要么更经常地轮询,或者两者兼而有之.
可悲的是,没有免费的午餐:(