我有一個單例類:kCFErrorDomainCFNetwork錯誤-1005 AFNetworking
+(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);
}];
此創建了該URL是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.)"}
我無法計算出會導致此問題的原因。謝謝
錯誤代碼'-1005'映射到'kCFURLErrorNetworkConnectionLost'似乎連接被截斷,當你通過AFNetworking請求它 – rckoenes