2010-09-15 47 views
0

我有一個帶有四個選項卡欄項的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] - 方法。

+0

我不知道爲什麼會發生這種情況。但是自從我發佈這個帖子以來,它再也沒有發生過,所以它已經是別的了...... – 2010-09-21 15:29:46

回答

0

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

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

所以答案是:檢查與Reachability的互聯網連接,並通知用戶是否應用程序要求這樣做。

0
**use this in dealloc method** 

-(void)dealloc 
{ 

    [locationManager stopUpdatingLocation]; 

locationManager.delegate=nil; 

[locationManager release]; 
} 

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