【发布时间】:2015-12-11 15:45:54
【问题描述】:
您好,最近发布了 iOS 9 GM 种子版本,我看到位置更新(allowDeferredLocationUpdatesUntilTraveled:timeout:) 没有延迟。我收到错误 kCLErrorDeferredFailed - 位置管理器由于未知原因未进入延迟模式。
由于这个错误,它根本没有进入延迟模式,并且位置更新不断触发。 用于在 iOS 8.4 及以下版本中工作的相同代码。它消耗了我设备的很大一部分电池。 我们是否需要为 iOS 9 明确设置或提及任何内容。在 Apple 文档中没有找到任何内容?
-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
if (!self.deferringUpdates) {
[self.locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:30];
self.deferringUpdates = YES;
}
}
-(void)locationManager:(CLLocationManager *)manager
didFinishDeferredUpdatesWithError:(NSError *)error {
// Stop deferring updates
self.deferringUpdates = NO;
}
我还设置了allowBackgroundLocationUpdates 属性,但即使这样也无济于事。
self.locationManager.allowsBackgroundLocationUpdates=YES;
在 iOS 9 及更高版本中,无论部署目标如何,您还必须将位置管理器对象的 allowedBackgroundLocationUpdates 属性设置为 YES 才能接收后台位置更新。默认情况下,此属性为 NO,并且在您的应用主动需要后台位置更新之前,它应该保持这种状态。
Reduce Location Accuracy and Duration
请告诉我我还需要做什么
谢谢
【问题讨论】:
-
您是否将准确度设置为最佳,将距离过滤器设置为无?
标签: ios core-location ios9