5

I have a singleton class:

+(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;
}

And in a controller I am calling this like so:

 [[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);
                            }];

The url this creates is http://node-hnapi.herokuapp.com/news which is a valid and working url. But the error message returned is

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.)"}

I can't work out what would be causing this issue. Thanks

joshuahornby10
  • 4,222
  • 8
  • 36
  • 52
  • Error code `-1005` maps to `kCFURLErrorNetworkConnectionLost` it seems that the connection is getting cut off when you are requesting it via the `AFNetworking` – rckoenes Jul 08 '14 at 08:02

2 Answers2

10

this error always appeared when the connection fails .. if your connection work fine just try to restart the iPhone simulator spicily with iPhone 6 simulator ...!

check link : NSURLConnection GET request returns -1005, "the network connection was lost"

Community
  • 1
  • 1
Saleh AlDhobaie
  • 311
  • 4
  • 9
3

Look in the CFNetworkErrors header files for CFNetwork Framework.

In Xcode navigate to

ProjectName > Frameworks > CFNetwork.framework > Headers > CFNetworkErrors.h

iCyberPaul
  • 650
  • 4
  • 15