kCFErrorDomainCFNetwork错误-1005 AFNetworking

时间:2014-07-08 07:54:13

标签: ios objective-c afnetworking afnetworking-2

我有一个单身人士课程:

+(id)sharedClient
{
static HackerNewsClient *__instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    NSURL *url = [NSURL URLWithString:@"http://node-hnapi.herokuapp.com"];
    __instance = [[HackerNewsClient alloc] initWithBaseURL:url];
});

return __instance;
}

在控制器中,我这样称呼它:

 [[HackerNewsClient sharedClient]GET:@"/news"
                         parameters:nil
                            success:^(NSURLSessionDataTask *task, id responseObject) {

                                NSArray *posts = [self parseEpisodeJSONData:responseObject];
                                completion(posts);
                            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                NSLog(@"ERROR: %@", error);
                            }];

这个创建的网址是http://node-hnapi.herokuapp.com/news,这是一个有效且有效的网址。但返回的错误消息是

2014-07-08 08:51:15.942 hn[27435:1627947] ERROR: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x10ba2bf70 {NSErrorFailingURLStringKey=http://node-hnapi.herokuapp.com/news, NSErrorFailingURLKey=http://node-hnapi.herokuapp.com/news, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x10ba22ff0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}

我无法解决导致此问题的原因。感谢

2 个答案:

答案 0 :(得分:10)

连接失败时总会出现此错误。 如果您的连接工作正常,请尝试使用iPhone 6模拟器重新启动iPhone模拟器......!

检查链接:NSURLConnection GET request returns -1005, "the network connection was lost"

答案 1 :(得分:3)

查看CFNetwork Framework的CFNetworkErrors头文件。

在Xcode中导航到

ProjectName>框架> CFNetwork.framework>标题> CFNetworkErrors.h