AFNetworking 3.0 및 날씨 응용 프로그램 용 CLLocation으로 작업하고 있습니다.AFNetworking with CLLocation 오류가 발생합니다
버튼을 클릭하면 API가 위치로 업데이트해야합니다. 하지만 위치 업데이트 후 오류가 발생합니다.
날씨 정보를 얻으려면 세계 날씨 api를 사용하고 있습니다. 오류가
,
오류 도메인 = com.alamofire.error.serialization.response 코드 = -1011 "요청 실패 : 금지 (403)" 사용자 정보 = {com.alamofire합니다. serialization.response.error.response = {URL : http://api.worldweatheronline.com/free/v1/weather.ashx?format=json&key=1b8c4f157aec499cba0120254161609&num_of_days=5&q=19.017615%2C72.856164} {상태 코드 : 403, 헤더 { "Access-Control-Allow-Origin"= "*"; 연령 = 0; "Cache-Control"= "공개, 최대 연령 = 120"; 연결 = "연결 유지"; "Content-Encoding"= gzip; "Content-Length"= 96; "Content-Type"= "application/json; charset = utf-8"; 날짜 = "2016 년 9 월 19 일 월요일 05:53:12 GMT"; 만료 = "월요일, 2016 년 9 월 19 일 05:55:13 GMT"; Vary = "Accept-Encoding"; Via = WebCelerate; "X-Cache"= MISS; "X-Powered-By"= "ASP.NET"; "X-Webcelerate"= "WebCelerate - www.ukfast.co.uk/web-acceleration.html"; "X-node"= "zfdl_api_01"; "access-control-allow-headers"= "content-type"; }} = http://api.worldweatheronline.com/free/v1/weather.ashx?format=json&key=1b8c4f157aec499cba0120254161609&num_of_days=5&q=19.017615%2C72.856164 NSErrorFailingURLKey는, com.alamofire.serialization.response.error.data = 6f72223a 205b207b 226d7367 223a2022 41,504,920 6b657920 646f6573 206e6f74 20,686,176 65,206,163 63,657,373 20746f20 7265736f 74,686,520 75,726,365 2e22207d 205d207d 7D < 7b202264 61,746,122 22,657,272 3a207b20> NSLocalizedDescription = 요청 실패 : 금지됨 (403)}
나는 넷에있는 모든 기사를 참조했지만 이에 대한 적절한 대답을 찾을 수 없습니다.
나는이 기능을 수행하기위한 몇 가지 방법, I라는 API 버튼을 탭하면이 방법은 전화
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{NSLog(@"location updated");
// Last object contains the most recent location
CLLocation *newLocation = [locations lastObject];
// If the location is more than 5 minutes old, ignore it
if([newLocation.timestamp timeIntervalSinceNow] > 300)
return;
[self.locationManager stopUpdatingLocation];
WeatherHTTPClient *client = [WeatherHTTPClient sharedWeatherHTTPClient];
client.delegate = self;
[client updateWeatherAtLocation:newLocation forNumberOfDays:5];
}
- (void)weatherHTTPClient:(WeatherHTTPClient *)client didUpdateWithWeather:(id)weather
{
self.weather = weather;
self.title = @"API Updated";
[self.tableView reloadData];
NSLog(@"API updated");
}
- (void)weatherHTTPClient:(WeatherHTTPClient *)client didFailWithError:(NSError *)error
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
NSLog(@"error - %@", error);
}
있습니다. 그리고 위치를 업데이트하고 tableview에서 데이터를 제공하십시오. 그러나 그것은 작동하지 않습니다.
버튼 방법은 : 나는 AFNetworking 데모에 대한이 튜토리얼을 다스 려하고
- (IBAction)apiTapped:(id)sender
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
self.locationManager.distanceFilter=kCLDistanceFilterNone;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startMonitoringSignificantLocationChanges];
[self.locationManager startUpdatingLocation];
NSLog(@"apiTapped");
}
, 그 튜토리얼 모든 사항에 따라
https://www.raywenderlich.com/59255/afnetworking-2-0-tutorial
나를 형성 AFNetworking 2.0에서 그들을 위해 잘 작동되지 않고, .내 코드의 문제점은 무엇입니까?
서버가 SSL 인증을받은 경우 http 대신 https를 사용하십시오. –