2009-11-03 2 views
1

sendSynchronousRequest 실패에 문제가 있습니다. 현재 지리적 위치 정보를 얻고 사용자가 "허용하지 않음"을 표시 한 후에 만 ​​실패합니다. 그리고 3.1.2에서 발생합니다. (. 지금까지 내가 말할 수는 3.0.1에서 잘 작동합니다.)"Do not Allow"위치 가져 오기 후 sendSynchronousRequest가 3.1.2에서 실패합니다.

가 여기에 내가 할 수있는 작업은 다음과 같습니다

내가 그것을 거의 아무 상관이 매우 기본적인 테스트 응용 프로그램을 설정합니다. applicationDidFinishLaunching에서 나는 여기에 내 기능, 테스트에 호출을 추가 :

- (void) test 
{ 
CLLocationManager *mLM; 

mLM = [[CLLocationManager alloc] init]; 
mLM.delegate = self; 

if ([mLM locationServicesEnabled]) 
{ 
    [mLM startUpdatingLocation]; 
} 
} 

내 대리인이 방법은 매우 간단도 있습니다

- (void) sendRequest 
{ 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
[request setURL:[NSURL URLWithString:@"https://theurl"]]; // this is actually a valid URL, changed here for privacy 
[request setHTTPMethod:@"GET"]; 
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData]; 

NSString *unpw = @"username:password"; 
NSString *base64 = [NSString base64StringFromString:unpw]; 
[request addValue:[NSString stringWithFormat:@"Basic %@", base64] forHTTPHeaderField:@"Authorization"]; 

NSURLResponse *response = nil; 
NSError *error = nil; 
NSData *respdata = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

[request release]; 
} 
:

마지막으로
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
[manager stopUpdatingLocation]; 
[self sendRequest]; // succeeds 
} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
[manager stopUpdatingLocation]; 
[self sendRequest]; // fails 
} 

, 여기 내 위치한 sendRequest입니다

sendSynchronousRequest에 대한 호출이 중단됩니다. 이것은 매우 실망 스러웠습니다. 누구든지 아이디어가 있습니까?

+0

URL에 네트워크 문제가 있습니까? 전화가 무한정 끊어지지 않습니까? –

+0

사용자가 geolocation fetch를 허용하면 sendSynchronousRequest는 정상적으로 성공합니다. 사용자가 3.1.2에서 geolocation 가져 오기에 "허용하지 않음"이라고 말한 이후를 제외하고는 항상 다른 모든 곳에서 잘 작동합니다. 나는 찾아 내기 위해 몇 분 이상 기다리지 않고 있지만, 무기한으로 기다리는 것처럼 보입니다. – Henning

+0

데이터 포인트로, 자체 스레드에서 sendRequest를 실행 해보십시오 (NSInvocationOperation 만 사용하십시오). – nall

답변

1

이렇게하면 효과가 있습니다. mLm이 클래스의 부울 값인지 확인하십시오.

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
[self.mLm release]; 
self.mLM = [[CLLocationManager alloc] init]; 
self.mLM.delegate = nil; 

[self sendRequest]; // fails - This time it will work!!! 
} 
+0

고마워요. 거의 고쳐졌지만 꽤 아닙니다. sendRequest가 성공했지만 나중에 실패했습니다. 하지만 조금 놀았고 작동하는 코드의 작은 변형이 발견되었습니다. \t \t [mLM stopUpdatingLocation]; \t mLM.delegate = nil; \t [mLM 방출]; \t mLM = [[CLLocationManager alloc] init]; \t mLM.delegate = 자기; – Henning

관련 문제