2010-12-28 4 views
0

일부 위치 데이터가 포함 된 클래스 인스턴스를 만드는 응용 프로그램이 있습니다.appDelegate에서 CLLocation 속성을 요청할 때 응용 프로그램이 충돌합니다.

앱 대리인에서 위치 서비스를 설정하고 위치 데이터를 가져 오기 시작합니다.

다른 클래스의 CLLocation 인스턴스에 연결할 수 있도록 최신 위치를 속성으로 선언합니다.

내 캡처 클래스는 init 메서드가 호출 될 때 호출 할 때 CLLocation을 가져옵니다.

//Designated initialiser 
-(id) initWithVideoPath:(NSString *) vPath 
       userNotes:(NSString *) uNotes 
     retentionState:(NSString *) rState 

{ 

    //Call the super classes designated initializer 
    [super init]; 

    //Get a pointer to the application delegate so we can access the location props 
    Rolling_VideoAppDelegate *appDelegate = (Rolling_VideoAppDelegate*)[UIApplication sharedApplication].delegate; 



    //If superclass failed to init 
    if (!self) 
     return nil; 



    //Give the variables some initial values 
    [self setVideoPath:vPath]; 
    [self setUserNotes:uNotes]; 
    [self setRetentionState:rState]; 
    dateCreated = [[NSDate alloc] init]; 


    mp = [[MapPoint alloc]initWithCoordinate:[[appDelegate latestLocation]coordinate]];//get the location from the coords from appDelegate 

    return self; 

    [dateCreated release]; 

} 

그러나 mapPoint init을 호출하면 앱이 다운됩니다. 문제는 제대로 CLLocation 정보를 얻지 못한다는 것입니다.

아무도 도와 줄 수 있습니까? 사전에

감사합니다,

리치

+0

LocationManager를 처음 시작할 때'latestLocation' ivar이 초기화되지 않았다고 생각합니다. '-application : didFinishLaunchingWithOptions :'메소드에서 다음과 같이 초기화하십시오 :'latestLocation = [[CLLocation alloc] initWithLatitude : 0.0f longitude : 0.0f];'. 제대로 출시하는 것을 잊지 마십시오. –

답변

0

나는 원래 솔루션이 작동하지 않는 이유를 아직 잘 모르는, 그래서 사람이 어떤 통찰력이있는 경우 계몽 마십시오.

내가 그러나 내가 위도 긴 NSUserDefaults는 CLLocation 객체 (NSCoding 호환성)를 저장하지 않으므로, 상기 캡처에서 그들을 재구성을 탈출하는 데 필요한 사용 NSUserDefaults

latestLocation = newLocation;//Make latest location the same as NewLocation 

    //Use NSUser Defaults to save the CLLocation instance 
    NSUserDefaults *location = [NSUserDefaults standardUserDefaults]; 
    [location setDouble:latestLocation.coordinate.latitude forKey:@"lat"]; 
    [location setDouble:latestLocation.coordinate.longitude forKey:@"longd"]; 

주위에 약간 우아 작업을 일한

수업;

NSUserDefaults *location = [NSUserDefaults standardUserDefaults];//Get a handle to the user defaults 
    CLLocationDegrees lat = [location doubleForKey:@"lat"]; 
    CLLocationDegrees longd = [location doubleForKey:@"longd"]; 
    CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:lat longitude:longd]; 

    mp = [[MapPoint alloc]initWithCoordinate:[currentLocation coordinate]];//get the location from the coords from appDelegate 
+1

didUpdateToLocation에서, 그것을 설정할 때'self.latestLocation = newLocation;'을 사용하여 값을 유지하십시오. – Anna

+0

예! 보존이 문제였습니다. 간단한 보유 증가로 문제가 해결되었습니다. – Shadrax

관련 문제