我正在使用Tony Million 的可达性代码,并且在无法访问的块中,我试图暂停下载,但每次在下载暂停之前互联网断开连接AFNetworking返回失败并显示错误消息“网络连接丢失”因此无法恢复下载所以应该做什么?
这就是我在Application Delegate中所做的
__weak MTCAppDelegate *weakself = self;
Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];
reach.reachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
[[AFDROSingleton sharedInstance] resume];
for (UIView *subview in [weakself.window subviews]) {
if (subview.tag == 20) {
[subview removeFromSuperview];
}
}
});
};
reach.unreachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
MTCReachability *reach = [[MTCReachability alloc] initWithFrame:weakself.window.frame];
[reach setTag:20];
[weakself.window addSubview:reach];
[weakself.window bringSubviewToFront:reach];
[[AFDROSingleton sharedInstance] pause];
});
};
[reach startNotifier];