2011-03-05 2 views
0

내 싱글 톤 내의 CLLocationManager가 작동하지 않는 이유는 무엇입니까? 나는이 코드를 가져 갔다. http://jinru.wordpress.com/2010/08/15/singletons-in-objective-c-an-example-of-cllocationmanager/싱글 톤 LocationManager가 업데이트를 시작합니까?

그의 코드를 전혀 바꾸지 않았다.

- (CLLocationManager *)locationManager { 

    if (locationManager != nil) { 
     return [LocationController sharedInstance].locationManager; 
    } 

    self.locationManager = [LocationController sharedInstance]; 
    [LocationController sharedInstance].locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 


    return [LocationController sharedInstance].locationManager; 
} 
  • (공극)이있는 viewDidLoad {[슈퍼의 viewDidLoad];

    // Start the location manager. 
    [LocationController sharedInstance].delegate = self; 
    //[[self locationManager] startUpdatingLocation]; 
    
    [[LocationController sharedInstance].locationManager startUpdatingLocation]; 
    

답변

2

여기에서 (CLLocationManager *) locationManager 메서드를 달성하려는 것이 무엇인지 잘 모르겠습니다.

- (id)init 
{ 
    self = [super init]; 
    if (self != nil) { 
     self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    } 
    return self; 
} 

을 그리고 당신은 위치를 업데이트하기 위해 다른 컨트롤러의 단일 개체를 호출 할 때, 당신은 전화를 할 수 있어야한다 : 그러나 LocationController.h의 init 함수에서,이 같은 것을 추가해야

 [[LocationController sharedInstance].locationManager startUpdatingLocation]; 

컨트롤러의 대리자 메서드 - (void) locationUpdate :(CLLocation *) 위치도 구현해야합니다.

내 게시물이 없었다면 이번에 도움이되기를 바랍니다.

0

아마도 문제는 대리자입니다. 이 파일은 싱글 톤이 아니라 파일을 가리 킵니다.

0

- (CLLocationManager *)locationManagerLocationController 라인

self.locationManager = [LocationController sharedInstance]; 

의 방법이라고 가정하면 유형 CLLocationManager이다 self.locationManager에 LocationController의 싱글 인스턴스를 지정으로 이해되지 않는다.