当切换选项卡时,LocationManager仍然存在
问题描述:
我有一个带有四个选项卡栏项的TabBarApplication。当切换选项卡时,LocationManager仍然存在
我的第三个选项卡使用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;
}
}
但是当我切换标签第四,这happends:
我得到的消息的UIAlertView中:
Unknown network error.
不与CLLocationManager死的时候切换选项卡? 我在dealloc方法中调用了[release] - 方法。
答
我认为这与我没有实现Reachability来检查网络连接有关。
这也是App Store指南(或您称之为)的要求。
所以答案是:检查与Reachability的互联网连接,并通知用户是否应用程序要求这样做。
答
**use this in dealloc method**
-(void)dealloc
{
[locationManager stopUpdatingLocation];
locationManager.delegate=nil;
[locationManager release];
}
//...........cheers.
我不知道为什么会发生这种情况。但是自从我发布这个帖子以来,它再也没有发生过,所以它已经是别的了...... – 2010-09-21 15:29:46