有什么方法可以告诉我 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/