Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - The network connection was lost" error while Downloading file using AFNetworking

I am using Reachability Code of Tony Million and in the unreachable block i am trying to pause the download but each time the internet Disconnects before the download is paused AFNetworking returns with failure with error message "The network connection was lost" thus unable to resume the download so what should be Done?

This is what i have done in 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];
like image 474
Quamber Ali Avatar asked Jun 10 '13 11:06

Quamber Ali


1 Answers

There is reachability code from the Apple sample that has been updated to ARC.

I've put it into the Reachability project in Xcode 4.6.3. If you are interested I can send your way if you need it.

like image 150
Alex Zavatone Avatar answered Oct 21 '22 04:10

Alex Zavatone