I have a Nsurlsesiondownloadtask
running which I use to download an XML file locally hosted at say : url - http://10.232.254.59/catalogue.xml
Problem is when I use url - http://10.232.254.59/catalogue.x or
url - http://10.232.254.59/catal or any other combination without changing the IP, didcompletewitherror
delegate gives me error= (null).
// MainViewController.m
@interface MainViewController ()
{
NSURLSessionDownloadTask *download;
}
@property(nonatomic,strong)NSURLSession *backgroundSession;
- (void)viewDidLoad {
NSURLSessionConfiguration *ConfigurationObject = [NSURLSessionConfiguration defaultSessionConfiguration];
ConfigurationObject.timeoutIntervalForRequest = 10.0;
ConfigurationObject.timeoutIntervalForResource = 10.0;
self.backgroundSession = [NSURLSession sessionWithConfiguration:ConfigurationObject delegate:self delegateQueue:nil];
[self LoadMediaUrl_StartTask_StartActivityIndicator];
}
-(void)LoadMediaUrl_StartTask_StartActivityIndicator{
NSURL *url ;
url = [self mediaUrlFromSettings];
if(url.absoluteString.length != 0){
download = [self.backgroundSession downloadTaskWithURL:url];
[download resume];
--do more stuff---
}
}
- (void)URLSession:(NSURLSession *)session downloadTask:(nonnull NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(nonnull NSURL *)location{
NSLog(@"didFinishDownloadingToURL called");
NSFileManager *fileManager = [NSFileManager defaultManager];
dispatch_async(dispatch_get_main_queue(), ^{
*** start the parser ***
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:[NSString stringWithFormat:@" Catalogue Download Success! Press OK to Load New Media List."] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];
alert.tag = ALERT_VIEW_DOWNLOAD_SUCCESS;
[alert show];
});
-(void)URLSession:(NSURLSession *)session task:(nonnull NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error
{
NSLog(@"didCompleteWithError error : %@",[error localizedDescription]);
if(error != nil){
dispatch_async(dispatch_get_main_queue(), ^{
[self.downloadActivityIndicator stopAnimating];
[self.downloadProgressView setHidden:YES];
self.DownloadImageView.alpha = 1.0;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[NSString stringWithFormat:@" Catalogue Download Failed ! %s%@","\n",[error localizedDescription]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Retry", nil];
alert.tag =ALERT_VIEW_DOWNLOAD_FAILED;
[alert show];
});
}
download = nil;
}
I get proper error in didCompleteWithError
when IP is changed but not when I change IP/* , because of which even in case of bad url , download success alert shows up.
I also receive the didFinishDownloadingToURL
delegate call even in bad url case .
I am calling LoadMediaUrl_StartTask_StartActivityIndicator
at few more places and using the same backgroundSession obj.
Could anyone please tell me what might be the cause ?