What I am trying to do it to resume and queue from the same point as where in was when network connection was lost . My problem is not with reachability but rather resumption of download. I have spend whole weekend but have had no luck .
Would hugely appreciate any help.
Code below has method commenceDownloadIfReachabilityIsOkay
which does get called when network is resumes but progress bar does not move and I do not see any activity to tell if download has resume.
This method gets called frin IBAction in controller
- (void) downloadFile:(UIProgressView*)locprogressView;
{
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
[hostReachable startNotifier];
if (![self asiqueue]) {
[self setAsiqueue:[[[ASINetworkQueue alloc] init] autorelease]];
}
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/Tests/the_great_american_novel.txt"];
self.request = [ASIHTTPRequest requestWithURL:url];
_progressView=locprogressView;
self.progressView= locprogressView;
[asiqueue cancelAllOperations];
[asiqueue setDownloadProgressDelegate:self.progressView];
[asiqueue setDelegate:self];
[asiqueue setRequestDidFinishSelector:@selector(queueComplete:)];
[asiqueue setShowAccurateProgress:YES];
// [queue setr
[request setDelegate:self];
// [request setDidReceiveDataSelector:@selector(didReceiveData:)];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setAllowResumeForFileDownloads:YES];
[[self asiqueue] addOperation:request]; //queue is an NSOperationQueue
[[self asiqueue]go ];
}
This method gets called from checkNetworkStatus
and I want it to resume download
- (void)commenceDownloadIfReachabilityIsOkay
{
if (self.asiqueue && self.hostActive && self.internetActive)
{
[[self asiqueue]go ];
}
}
This method just keeps polling to check network status - Taken from How to check for an active Internet connection on iOS or OSX?
- (void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(@"A gateway to the host server is down.");
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"A gateway to the host server is working via WIFI.");
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"A gateway to the host server is working via WWAN.");
self.hostActive = YES;
break;
}
}
[self commenceDownloadIfReachabilityIsOkay];
}
If I understand your code correctly, it is hoping that calling:
[[self asiqueue]go ];
will result in a ASIHTTPRequest that failed sometime ago getting requeued and starting download again. There's two reasons this won't work:
go
on a queue that go
has already been called on does
nothingThe solution is to requeue the request to restart it.
Also, http://allseeing-i.com/ASIHTTPRequest/How-to-use#resuming_interrupted_downloads says:
Additionally, you must set a temporary download path yourself (
setTemporaryFileDownloadPath
), with the path of the partial data.
which your code doesn't seem to be doing. (You also need to setDownloadDestinationPath
)