我试图在连接失败时测试我的应用程序的行为。我正在iPad上关闭WiFi测试。当Restkit试图调用Web服务,我得到以下错误:RestKit连接失败委托
CPL[7713:6203] E restkit.network:RKRequest.m:545 Failed to send request to https://xxxxxxxx/APNS_WebService/rest/operations/initializeDevice?deviceID=c4a17f855d3cc824b174b71908480d4e505ebfb221cb4643da9270a07344c367 due to unreachable network.
的问题是,我想在处理委托的回调方法这种情况,但没有委托方法被调用。我已经在请求上设置了委托,并且实现了requestDidFailLoadWithError,requestDidCancelLoad,requestDidTimeout和objectLoaderDidFailWithError。这些都不是所谓的。
为什么不是我的代表被调用?
编辑:设置里面RKRequest.m断点后,我看到下面的行实际上是在被执行:
[self performSelector:@selector(didFailLoadWithError:) withObject:error afterDelay:0];
然而,我的委托方法没有得到所谓的。
此处,我设置委托:
request = [client requestWithResourcePath:[NSString stringWithFormat:@"/initializeDevice?deviceID=%@",deviceID]];
request.delegate=self;
[request sendAsynchronously];
编辑2:其实,在RKRequest.m行,我张贴以上只是调用RKRequest另一种方法,但事实并非如此。在didFailLoadWithError中放置一个断点表明该代码永远不会到达。我不明白为什么这不起作用。
将performSelector更改为常规方法调用会出现在表面上,以使我找到我正在查找的行为。这会打破什么?我想我不知道为什么performSelector被用来调用同一个类中的方法。
编辑3:按照要求,这里是我的委托方法:
-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{
NSLog(error.domain);
NSLog([NSString stringWithFormat:@"%d",error.code]);
NSLog(error.localizedDescription);
NSLog(error.localizedFailureReason);
[request reset];
[request send];
}
谢谢,我会研究一下。 –
请参阅我的编辑。 –
你为什么不介入'didFailLoadWithError:'看看为什么不调用委托方法?它可能取决于您选择的缓存策略... – sergio