2011-09-09 66 views
1

我没有得到GPS位置更新。我正在使用iPad2来运行代码。这是我的代码:我没有得到GPS位置更新。我错过了什么?

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

     //location 
     locationManager = [[[CLLocationManager alloc] init] autorelease]; // Create new instance of locMgr 
     locationManager.delegate = self; 

     locationManager.distanceFilter = kCLDistanceFilterNone; 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

     [locationManager startUpdatingLocation]; 
     NSLog(@"locationManager startUpdatingLocation"); //this core runs correctly 

... 
} 

- (void)locationManager:(CLLocationManager *)manager 
    didFailWithError:(NSError *)error 
{ 
    NSLog(@"Error: %@", [error description]); 
} 


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    location = [newLocation description]; 
    NSLog(@"new location: %@", location); //never printed 
} 

我应该允许在首选项中的位置吗?我期待iPad要求分享位置的权限,但我没有得到任何。

谢谢

+0

如果一点儿也不问权限自动,那么你应该已经尝试允许在首位置......如果甚至一点儿也不工作,那么这件事情隐藏,因为你的代码看起来不错 – tipycalFlow

+0

@tipycalFlow我跑来自xCode的应用程序,所以我没有在首选项中的应用程序。我的意思是,在这个应用程序的首选项中无法启用/禁用位置权限。 (全球一个启用)。 – aneuryzm

+0

我应该在我的应用程序委托中添加代码行以注册位置通知吗?我不明白这一点.. – aneuryzm

回答

1

我其实去除自动释放并增加在dealloc中释放,仅此而已。

1

locationManager保留属性?如果不是,使它之一,在页头+初始化行前加self.这样的LocationManager不是在该方法月底公布:

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 

dealloc另外补充[locationManager release];

+0

对不起,迟到的答复。问题的确是关于内存管理,但解决方案更简单。 – aneuryzm

相关问题