Ios 使用ARC调用和释放CLLocationManager
我的应用程序只能获取用户的当前位置一次 它使用位置管理器和代理成功地完成了这项工作。当我第一次获得位置后,我的代理将经理呼叫到Ios 使用ARC调用和释放CLLocationManager,ios,cllocationmanager,Ios,Cllocationmanager,我的应用程序只能获取用户的当前位置一次 它使用位置管理器和代理成功地完成了这项工作。当我第一次获得位置后,我的代理将经理呼叫到stopdationlocation 由于我使用的是ARC,并且在我的应用程序运行的所有时间内都保留了这个类的一个实例,所以我的CLLocationManager实例保留在内存中 我知道GPS服务非常耗电,但它是否也有同样的效果,而我实际上不消耗更多的事件?它还能继续工作吗 我想知道我是否应该添加一些逻辑来发布它 试试下面 -(void)updateLoc { i
stopdationlocation
由于我使用的是ARC,并且在我的应用程序运行的所有时间内都保留了这个类的一个实例,所以我的CLLocationManager实例保留在内存中
我知道GPS服务非常耗电,但它是否也有同样的效果,而我实际上不消耗更多的事件?它还能继续工作吗
我想知道我是否应该添加一些逻辑来发布它 试试下面
-(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;
}
使用可以使用self.locationManager=nil;注意不要只使用第一个位置-它可能不太准确-您可以检查CLLocation的HorizontalAccurance属性以确定是否要等待其他更新
didUpdateLocation:toLocation
已弃用-您只需实现didUpdateLocations: