0

我有一个使用位置服务的应用程序。在我的 appdelegate 中,我正在初始化我的位置管理器属性

if(self.locationManager == nil)
    {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];  // allocate cllocationmanager property
        self.locationManager.delegate = self;  // confirm the delegate 
        [self.locationManager startUpdatingLocation];  // start updating for location 
    }

并且位置管理器委托在 dealloc 方法中为零

- (void)dealloc
{
   [_window release];
   [_viewController release];

 // [locationManager release];
   self.locationManager.delegate = nil;
   [super dealloc];
}

当我从设置中切换位置服务时,应用程序崩溃 10 次

在仪器中调试后,这是显示的错误

在此处输入图像描述

请提出相同的修复方法。

4

2 回答 2

0

如果您还没有与您的 cllocationmanager 属性同名的实例变量,请创建一个实例变量,并且仅在您设置时调用 self.locationmanager ,如下所示

   if (nil == locationManager){
        self.locationManager = [[CLLocationManager alloc] init];
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        locationManager.delegate = self;
        [locationManager startUpdatingLocation];
        startLocation = nil;
    }

这是为 arc 编写的,因此如果需要,请添加您的自动释放。

于 2013-07-20T12:22:37.970 回答
0

你还没有告诉locationManager- stopUpdatingLocationApple文档

于 2013-07-20T14:40:03.273 回答