Quamber Ali
Quamber Ali

Reputation: 2171

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];

Upvotes: 4

Views: 2319

Answers (1)

Alex Zavatone
Alex Zavatone

Reputation: 4323

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.

Upvotes: 1

Related Questions