objective-c - 如何检测由于没有连接而调用 didFailWithError ?

标签 objective-c ios restkit

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

相关文章:

ios - Xcode 10 和 Xcode 11 代码完成将所有对象显示为 "int *"

ios - 我什么时候需要从服务器加载通知数据?

objective-c - 如何在iPhone中更改UITextField的颜色?

ios - 如何在自定义 UICollectionView 旋转后触发 drawrect?

iphone - 在 Restkit 中处理 NSAsserts 抛出

objective-c - 相当于ARC下保留实例变量

objective-c - 创建 NSWindow 的问题

ios - 未为测试目标生成核心数据类

ios - 具有本地化键值的 NSPredicate

ios - 列表中列表的 RestKit 对象映射