Ios 使用CLLocation的AFN网络产生错误
我正在使用AFNetworking 3.0和CLLocation for weather应用程序 当我点击按钮时,API必须随位置更新。但它在更新位置后给了我错误 我正在使用世界天气api获取天气详细信息 错误是 Error Domain=com.alamofire.Error.serialization.response Code=-1011 “请求失败:禁止(403)” UserInfo={com.alamofire.serialization.response.error.response={URL: }{状态代码:403,标题{ “访问控制允许来源”=“*”; 年龄=0; “缓存控制”=“公共,最大使用年限=120”; 连接=“保持活动”; “内容编码”=gzip; “内容长度”=96; “内容类型”=“应用程序/json;字符集=utf-8”; 日期=“2016年9月19日星期一05:53:12 GMT”; Expires=“2016年9月19日星期一05:55:13 GMT”; Vary=“接受编码”; Via=WebCelerate; “X缓存”=未命中; “X-Powered-By”=“ASP.NET”; “X-Webcelerate”=“Webcelerate-www.ukfast.co.uk/web acceleration.html”; “X节点”=“zfdl_api_01”; “访问控制允许标头”=“内容类型”;}},NSErrorFailingURLKey=, com.alamofire.serialization.response.error.data=, NSLocalizedDescription=请求失败:禁止(403)} 我已经参考了网上所有的文章,但找不到正确的答案 我有一些执行此功能的方法Ios 使用CLLocation的AFN网络产生错误,ios,objective-c,cllocationmanager,cllocation,afnetworking-3,Ios,Objective C,Cllocationmanager,Cllocation,Afnetworking 3,我正在使用AFNetworking 3.0和CLLocation for weather应用程序 当我点击按钮时,API必须随位置更新。但它在更新位置后给了我错误 我正在使用世界天气api获取天气详细信息 错误是 Error Domain=com.alamofire.Error.serialization.response Code=-1011 “请求失败:禁止(403)” UserInfo={com.alamofire.serialization.response.error.response
- (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);
}
当我点击名为API的按钮时,这个方法调用。和更新位置,并在tableview中提供数据。但它不起作用
按钮方法是:
- (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");
}
我正在参考本教程进行AFNetworking演示
根据该教程,在AFNetworking 2.0中,他们的一切都很好,但不是我
那么我的代码有什么问题呢?您的客户端收到了
HTTP错误403禁止
这意味着
请求是有效的请求,但服务器拒绝响应
去吧。用户可能已登录,但没有必要的权限
资源的权限
因此,请检查您的授权状态。有关更多信息,请查看您的客户端收到的HTTP错误403禁止的链接,这意味着 请求是有效的请求,但服务器拒绝响应 去吧。用户可能已登录,但没有必要的权限 资源的权限
因此,请检查您的授权状态。有关更多信息,请查看链接我已经解决了问题 问题在于访问。我在世界天气与免费用户帐户。api的url是 因此,使用免费帐户,他们不提供对api的访问 我把网址改成
所以现在他们允许访问api,错误现在消失了。我已经解决了这个问题 问题在于访问。我在世界天气与免费用户帐户。api的url是 因此,使用免费帐户,他们不提供对api的访问 我把网址改成
因此,现在他们允许访问api,错误现在消失。如果您的服务器通过ssl认证,请使用https而不是http。如果您的服务器通过ssl认证,请使用https而不是http。