I have a NSURLSession
and a NSURLSessionDownloadTask
configured for downloading a file in background, if the download task in canceled by the user all the data is deleted and the storage space the file was using is freed, but if the app is closed from the multitasking dock the download task is terminated and gives an error but is not deleting the data and the temporal data for the file is still occupying storage space and is never freed. What do i need to do in order to free the space ?
This is my NSURLSession
configuration and error handling:
- (NSURLSession *)backgroundSession {
static NSURLSession *session = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *configuration;
if ([[UIDevice currentDevice].systemVersion hasPrefix:@"7"]) configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.visyon.pr"];
else configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.visyon.pr"];
configuration.sessionSendsLaunchEvents =YES;
session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
});
return session; }
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
if (error == nil) {
NSLog(@"Task: %@ completed successfully", task );
} else {
// [self hideActivity];
// [self showAlertBoxErrorDownload];
NSLog(@"Task: %@ completed with error: %@, %lu", task, [error localizedDescription], (long)error.code);
} self.downloadTask = nil; }
[NSURLSessionDownloadTask cancel]
– Vitelline<__NSCFBackgroundDownloadTask: 0x146d2f990>{ taskIdentifier: 2 }
then I close the app while the task is still downloading and when I open the app again I get the next error:Task: <__NSCFBackgroundDownloadTask: 0x135e24460>{ taskIdentifier: 3 } completed with error: unsupported URL, 18446744073709550614
– Vitelline