有没有办法告诉我何时调用 Restkit didFailWithError 函数的原因是缺少与服务器的连接?
-(void) objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error{
//What should I do here to know the server could not be reached?
}
有没有办法告诉我何时调用 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
}
}
需要帮助请叫我 :)
您应该可以查看NSError
类参考。
您将在哪里找到以下相关方法:
-(NSUInteger)code;
//A string containing the localized description of the error.
-(NSString *)localizedDescription;
因此,您将检查NSError
您收到的此方法的返回值。