有什么方法可以告诉我何时调用Restkit didFailWithError函数的原因是与服务器的连接断开?
-(void) objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error{
//What should I do here to know the server could not be reached?
}
最佳答案
在NSURLConnection
didFailWithError
方法中,我使用此代码,它可能适用于RESTKit
,但我不确定。我以为我会发布此内容,以便您至少可以检查一下(可能会有帮助):)
if (error)
{
NSLog(@"%@", [NSString stringWithFormat:@"Connection failed! Error code: %d - %@ %@", error.code, error.localizedDescription, [error.userInfo objectForKey:NSURLErrorFailingURLStringErrorKey]]);
if (error.code == -1009)
{
// This is the case that a connection failed based on bad connectivity
}
}
需要帮助请叫我 :)
关于objective-c - 如何检测在didFailWithError是否由于没有连接而被调用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12113431/