gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:27:38 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com