开发者

Releasing instance if service not enabled?

开发者 https://www.devze.com 2022-12-30 16:31 出处:网络
I would just like to check if I have this right, I am creating an instance of CCLocationManager and then checking if location services are enabled. If it is not enabled I then report an error, release

I would just like to check if I have this right, I am creating an instance of CCLocationManager and then checking if location services are enabled. If it is not enabled I then report an error, release the instance and carry on, does that look/sound right?

locationManager = [[CLLocationManager alloc] init];
BOOL supportsService = [locationManager locationServicesEnabled];

if(supportsService) {
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
} else {
    NSLog(@"Location services not enabled.");
    [locationManager release];
}
... 
...开发者_JAVA百科
... more code

cheers gary


To prevent errors further down you could set locationManager to nil after releasing. Other than that there's no problem with your approach.

0

精彩评论

暂无评论...
验证码 换一张
取 消