我正在使用Tony Million的可达性代码 并且在无法访问的块中我尝试暂停下载,但每次互联网断开连接之前,下载暂停 AFNetworking 返回失败并显示错误消息“网络连接丢失”因此无法恢复下载应该做什么?
这是我在应用程序代表
中所做的__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];
答案 0 :(得分:1)
Apple示例中的可访问性代码已更新为ARC。
我已将它放入Xcode 4.6.3中的Reachability项目中。如果您有兴趣,我可以根据您的需要发送。