2011-09-09 71 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

相關問題