【问题标题】:Calling and releasing CLLocationManager With ARC使用 ARC 调用和释放 CLLocationManager
【发布时间】:2014-07-21 08:46:05
【问题描述】:

我的应用应该只获取一次用户的当前位置。

使用位置管理器和委托成功地做到了。一旦我第一次得到位置,我的代表就会打电话给经理stopUpdatingLocation

由于我使用的是 ARC,并且在我的应用程序运行期间一直保留此类的一个实例,因此我的 CLLocationManager 实例保留在内存中。

我知道 GPS 服务非常耗电,但它是否具有相同的效果,而我实际上并没有消耗更多的事件?它继续工作吗?

我想知道我是否应该添加一些逻辑来发布它。

【问题讨论】:

  • 使用可以使用 self.locationManager = nil;
  • 注意只使用第一个位置 - 它可能不是很准确 - 您可以检查 CLLocation 的 Horizo​​ntalAccuracy 属性以确定是否要等待其他更新

标签: ios cllocationmanager


【解决方案1】:

尝试关注...

-(void)updateLoc
{
    if (self.locationManager != nil)
    {
        [self.locationManager stopUpdatingLocation];
        self.locationManager.delegate = nil;
        self.locationManager = nil;
    }

    self.locationManager = [[CLLocationManager alloc] init];    
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.delegate = self;
    self.locationManager.headingFilter = 1;

    self.locationManager.distanceFilter=10.0;
    [self.locationManager startUpdatingLocation];

}


-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    [self.locationManager stopUpdatingLocation];
    self.locationManager = nil;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{//Use if you are supporting iOS 5
    [self.locationManager stopUpdatingLocation];
    self.locationManager = nil;
}

【讨论】:

  • didUpdateLocation:toLocation 已弃用 - 您只需要实现 didUpdateLocations:
猜你喜欢
  • 1970-01-01
  • 2013-02-08
  • 2023-03-20
  • 1970-01-01
  • 2012-05-04
  • 2013-11-29
  • 2013-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多