有什么方法可以告诉我调用我的Restkit didFailWithError函数的原因是缺少与服务器的连接吗?
-(void) objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error{
//What should I do here to know the server could not be reached?
}
答案 0 :(得分:1)
在我使用此代码的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
}
}
如果您还需要其他信息,请告诉我们。)
答案 1 :(得分:0)
您应该可以查看NSError
class reference。
您将在哪里找到以下相关方法:
-(NSUInteger)code;
//A string containing the localized description of the error.
-(NSString *)localizedDescription;
因此,您将从您收到的NSError
检查此方法的返回值。