[英]iphone app crashes when location services are toggled
我有一个使用定位服务的应用程序。 在我的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方法中将位置管理器委托设为nil
- (void)dealloc
{
[_window release];
[_viewController release];
// [locationManager release];
self.locationManager.delegate = nil;
[super dealloc];
}
当我从设置切换位置服务时,该应用程序崩溃10次中的1次
在仪器中调试后,这是显示的错误
请建议同样的解决方法。
创建实例变量(如果您尚未创建的实例变量)与cllocationmanager属性的名称相同,并且仅在进行如下所示的设置时调用self.locationmanager
if (nil == locationManager){
self.locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
startLocation = nil;
}
这是为arc编写的,因此如果需要,请添加自动发布。
您尚未告诉locationManager
stopUpdatingLocation
- Apple文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.