Из этого форума я знаю, что это известная ошибка, о которой сообщалось Apple, но я обеспокоен тем, что утечка памяти продолжает увеличиваться при каждом вызове представления.
соответствующий код
-(IBAction)getlocationgo:(id) sender{
//NSAutoreleasePool *pool;
//pool = [[NSAutoreleasePool alloc] init];
self.locationManager=[[[CLLocationManager alloc]init]autorelease];
self.locationManager.delegate = self;
[locationManager startUpdatingLocation];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//mapView.showsUserLocation =YES;
//[pool release];
}
- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
switch([anError code])
{
case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
break;
case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
{UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Location Error"
message:@"Please enable Location Services in the Settings menu"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
[alert show];
[alert release];}
break;
case kCLErrorNetwork: // general, network-related error
{UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Location Error"
message:@"The Little Helper can't find you - please check your network connection or that you are not in airplane mode"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
[alert show];
[alert release];}
break;
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"thisruns");
MKCoordinateSpan span;
span.latitudeDelta =0.2;
span.longitudeDelta =0.2;
MKCoordinateRegion region;
region.span = span;
region.center = newLocation.coordinate;
[mapView setRegion:region animated:YES];
mapView.showsUserLocation =YES;
mapView.mapType = MKMapTypeHybrid;
latitude.text = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
longitude.text = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
NSString *newloc=longitude.text;
NSLog(@"long%f", newloc);
[locationManager stopUpdatingLocation];
}
собственность с этим
@property (nonatomic, retain) CLLocationManager *locationManager;
и он освобожден
mapView.delegate = nil;
[mapView release];
locationManager.delegate = nil;
[locationManager release];
Я уже несколько дней возвращаюсь к этому, любая помощь или советы будут великолепны.
Спасибо
Редактировать один
Пытаясь получить доступ к locationManager в делегате приложения, все работает, но нет обновления для местоположения из IBaction
Это код в IBaction, и результат из журнала (ноль)
LLHelperAppDelegate *appDelegate = (LLHelperAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.locationManager startUpdatingLocation];
appDelegate.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
NSLog(@"%@", [appDelegate locationManager]);