嗨,最近与iOS 9转基因种子版本出来,我看到位置iOS没有被推迟。我得到了错误的kCLErrorDeferredFailed -位置管理器没有进入延迟模式,原因不明。
因为这个错误,它根本没有进入延迟模式,并且位置更新一直在触发。在iOS 8.4及以下的versions.Its中,同样的代码会使我的设备的电池消耗掉很大比例。对于iOS 9,我们是否需要显式地设置或提及什么?
-(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;
}我还设置了allowsBackgroundLocationUpdates属性,但即使这样也没有帮助。
self.locationManager.allowsBackgroundLocationUpdates=YES;在iOS 9及更高版本中,无论部署目标如何,您还必须将位置管理器对象的allowsBackgroundLocationUpdatesproperty设置为YES,以便接收后台位置更新。默认情况下,此属性为NO,并且应该保持这种状态,直到应用程序主动要求后台位置更新时为止。
请告诉我我还需要做些什么
谢谢
https://stackoverflow.com/questions/32585166
复制相似问题