아래와 같이 로컬검색 기능을 만들었는데 NSURLErrorDomain error -1012(401 에러)만 나네요… 무엇이 문제일까요?
에러메시지:
2018-10-11 14:19:53.128163+0900 peachtime[17649:1036680] -Searcher _search: requestDataError : The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
/* parameter
* urlString: https://dapi.kakao.com/v2/local/search/keyword.json?query=사당&page=1
*/
- (void)_search:(NSString *)urlString {
NSString *encodedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:encodedUrlString];
NSError *requestDataError = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:[NSString stringWithFormat: @"KakaoAK @%@", KAKAO_REST_API_KEY] forHTTPHeaderField:@"Authorization"];
[request setTimeoutInterval:30.0];
NSData *jsonData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&requestDataError];
if (requestDataError) {
NSLog(@"requestDataError : %@", [requestDataError localizedDescription]);
BOOL enabled = self.delegate != nil && [self.delegate respondsToSelector:@selector(searcher:didFailSearchWithError:)];
if (enabled) {
[self.delegate searcher:self didFailSearchWithError:requestDataError];
}
} else {
NSMutableDictionary *receivedJson = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSArray *jsonArray = [receivedJson valueForKeyPath:@"channel.item"];
NSArray *items = [self _itemListWithJsonArray:jsonArray];
[self _didFinishSearch:items];
}
}