2010-07-06 3 views
1

iPhone OS 4.0에서 내 앱을 실행해야합니다. (시뮬레이터에서).CLLocation Manager Delegate가 iPhone OS 4.0에서 호출되지 않습니다.

-(BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [self newLocationUpdate]; 
} 

-(void)newLocationUpdate 
{ 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    [locationManager startUpdatingLocation]; 

} 

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation 
{ 
    [locationManager stopUpdatingLocation]; 
} 

이 CLLocationManager 대리자 메서드가 호출되지 않습니다. Delegate 메소드가 호출되도록 변경해야하는 항목은 무엇입니까?

답변

3

"locationManager"인스턴스가 조만간 출시 될 것으로 예상됩니다.

속성입니까?

locationManager = [[CLLocationManager alloc]] init]; 

에 : 그렇다면, 그때부터 변경

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

와 속성이 선언되어 있는지 확인합니다 :

@property (nonatomic, retain) CLLocationManager * locationManager; 

을 그리고 적절한 경우 나중에 그것을 해제하는 것을 잊지 마세요 .

+0

나는 보존 된 속성으로 인해 장기적으로 유지 보수가 더 간단해질 것이라는 데 동의하지만, 보존 된 속성에 보유 개수가 1 (alloc, init 및 no autorelease) 인 위치 관리자를 지정하면 결국 끝날 것입니다 보유 수는 2이고 손에 누출이 있습니다. 그러니 "자기"를 사용하십시오. 접근법을 유지하고 그 alloc-init의 끝 부분에 autorelease를 추가하십시오. – Heiberg

관련 문제