"허용하지 않음" 위치 가져오기 후 3.1.2에서 sendSynchronousRequest가 실패함
-
13-09-2019 - |
문제
나는 ~을 하는 데 문제가 있다 sendSynchronousRequest
실패.현재 지리적 위치를 얻으려고 시도하고 사용자가 "허용 안 함"을 누른 후에만 실패합니다.그리고 이는 3.1.2에서만 발생합니다.(내가 말할 수있는 한.3.0.1에서는 잘 작동합니다.)
내가하는 일은 다음과 같습니다.
나는 거의 아무것도 포함하지 않은 매우 기본적인 테스트 앱을 설정했습니다.~ 안에 applicationDidFinishLaunching
여기에 있는 내 함수 test에 대한 호출을 추가합니다.
- (void) test
{
CLLocationManager *mLM;
mLM = [[CLLocationManager alloc] init];
mLM.delegate = self;
if ( [mLM locationServicesEnabled] )
{
[mLM startUpdatingLocation];
}
}
내 대리자 메서드도 매우 간단합니다.
- (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는 다음과 같습니다.
- (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];
}
에 대한 호출 sendSynchronousRequest
멈춘다.이것은 매우 실망스러웠습니다.누구든지 어떤 아이디어가 있습니까?
해결책
이것은 마법처럼 작동할 것입니다.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!!!
}
제휴하지 않습니다 StackOverflow