0

我有一个带有四个标签栏项目的 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。

4

2 回答 2

0

我认为这与我没有实现可达性来检查网络连接有关。

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

所以答案是:使用 Reachability 检查 Internet 连接,并在应用程序需要时通知用户。

于 2010-09-28T10:38:35.063 回答
0
**use this in dealloc method**

-(void)dealloc
{

  [locationManager stopUpdatingLocation];

locationManager.delegate=nil;

[locationManager release];
}

//...........cheers.
于 2013-01-30T13:49:16.843 回答