在iOS中实现延迟的位置更新

时间:2013-11-19 00:10:32

标签: ios gps location cllocationmanager battery-saver

我正在尝试在我的iOS应用中实施延期位置更新功能。据我所知,此功能可显着降低使用GPS的位置感知应用的功耗。 Apple的文档以下面的代码为例:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
   [self.run addLocations:locations];
   if (!self.deferringUpdates) {
      CLLocationDistance distance = self.hike.goal - self.hike.distance;
      NSTimeInterval time = [self.nextAudible timeIntervalSinceNow];
      [locationManager allowDeferredLocationUpdatesUntilTraveled:distance
                                                     timeout:time];
   self.deferringUpdates = YES;
   }
}

但是,当我开始输入if (!self.d时,“deferringUpdates”属性不会显示。那是为什么?

有没有人成功实现过这项功能?如果是这样,请您分享您的实施情况?谢谢。

1 个答案:

答案 0 :(得分:0)

在复制的示例代码中deferringUpdates是您必须在CLLocationManagerDelegate对象上定义的属性。它不是框架定义或提供的东西。该示例代码不是您可以放入应用程序的完整实现。