xcode NSURLErrorDomain 错误代码 -1005

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26391189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:53:10  来源:igfitidea点击:

NSURLErrorDomain Error Code -1005

objective-cxcodexcode6cs193p

提问by NumberOneRobot

I'm working on the CS193p coursework from Stanford (I'm not a Stanford student I'm just trying to learn), assignment number 5, where we have to get images from Flickr using calls to the Flickr api. I'm only trying to download a list of the pictures and print them out to the console, but I'm getting an NSURLErrorDomain with code -1005. The error message I am printing out is below:

我正在研究斯坦福大学的 CS193p 课程(我不是斯坦福大学的学生,我只是想学习),作业编号 5,我们必须使用对 Flickr api 的调用从 Flickr 获取图像。我只是想下载图片列表并将它们打印到控制台,但我收到了代码为 -1005 的 NSURLErrorDomain。我打印出来的错误信息如下:

error: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn't be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7f9449c83df0 {NSErrorFailingURLStringKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, NSErrorFailingURLKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7f9449c7fca0 "The operation couldn't be completed. (kCFErrorDomainCFNetwork error -1005.)"}

错误:错误域=NSURLErrorDomain 代码=-1005“操作无法完成。(NSURLErrorDomain 错误-1005。)” UserInfo=0x7f9449c83df0 {NSErrorFailingURLStringKey= https://api.flickr.com/services/rest/?method= flickr.places.getTopPlacesList&place_type_id = 7&格式= JSON&nojsoncallback = 1&API_KEY = 4f9c3155b34836b2ac15318d98b93f3a,NSErrorFailingURLKey = https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a,_kCFStreamErrorDomainKey = 1 , _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7f9449c7fca0“操作无法完成。(kCFErrorDomainCFNetwork错误-1005。)”}

The Flickr API call is happening in the following method:

Flickr API 调用发生在以下方法中:

NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
NSURLSessionDownloadTask *downloadTask = [urlSession downloadTaskWithURL:[FlickrFetcherHelper URLforTopPlaces] completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
    NSArray *topPlaces;
    if (!error) {
        topPlaces = [[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:location] options:0 error:&error] valueForKeyPath:FLICKR_RESULTS_PLACES];
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        completionHandler(topPlaces, error);
    });
}];
[downloadTask resume];

I'm using xCode 6, not sure if that has anything to do with the problem. The same code was working a couple days ago, and I don't think I changed anything that would mess it up, but it clearly has.

我正在使用 xCode 6,不确定这是否与问题有关。相同的代码几天前还在工作,我认为我没有改变任何会搞砸的东西,但它显然有。

回答by Rhian Thomas

Are you using the iOS8 (iPhone 6 for example) simulator? If so, try changing to iPhone 5s. I was having the same problem and switched my simulator and all worked well again. I tried this after reading the following feedback: https://github.com/AFNetworking/AFNetworking/issues/2314

您使用的是 iOS8(例如 iPhone 6)模拟器吗?如果是这样,请尝试更换为 iPhone 5s。我遇到了同样的问题并切换了我的模拟器,并且一切正常。我在阅读以下反馈后尝试了这个:https: //github.com/AFNetworking/AFNetworking/issues/2314

回答by Roman Tataurov

Switch to iOS Simulator and do "Reset Content and Settings ..." from top menu.

切换到 iOS 模拟器并从顶部菜单执行“重置内容和设置...”。