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
Look in the CFNetworkErrors header files for CFNetwork Framework.
In Xcode navigate to
ProjectName > Frameworks > CFNetwork.framework > Headers > CFNetworkErrors.h
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With