一千萬個為什麽

搜索

切換選項卡時,LocationManager仍然存在

我有一個帶有四個標簽欄項目的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;
}

}

但當我將tab切換到第四個時,會發生這種情況:

我得到一個帶有消息的UIAlertView:

Unknown network error.

切換選項卡時CLLocationManager是否會死? 我在dealloc方法中調用了[release] -method。

最佳答案

我認為這與我沒有實現Reachability檢查網絡連接有關。

這也是App Store指南(或您稱之為)的要求。

So the answer is: Check for Internet connection with Reachability and inform the user if the application demands this.

轉載註明原文: 切換選項卡時,LocationManager仍然存在