切换选项卡时,LocationManager仍然存在

时间:2010-09-15 10:50:39

标签: cllocationmanager

我有一个带有四个标签栏项目的TabBarApplication。

我的第三个标签使用CLLocationManager来定位用户所在的位置等等。

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

[locationManager stopUpdatingLocation];
NSLog(@"error%@",error);
switch([error code])
{
    case kCLErrorNetwork:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please check your network connection or that you are not in airplane mode." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
        break;
    case kCLErrorDenied:{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You have denied to allow Berns to get your location. " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
        break;
    default:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unknown network error." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
        break;
}

}

但是当我将标签切换到第四个时,会发生这种情况:

我收到一条带有消息的UIAlertView:

Unknown network error.

切换标签时CLLocationManager是否会死? 我在dealloc-method中调用了[release] -method。

2 个答案:

答案 0 :(得分:0)

我认为这与我没有实现Reachability以检查网络连接有关。

这也是App Store指南(或您所称的)的要求。

所以答案是:检查具有可达性的Internet连接,并告知用户应用程序是否需要此功能。

答案 1 :(得分:0)

**use this in dealloc method**

-(void)dealloc
{

  [locationManager stopUpdatingLocation];

locationManager.delegate=nil;

[locationManager release];
}

//...........cheers.