diff --git a/Downloader.m b/Downloader.m index bf102688..b17187d8 100644 --- a/Downloader.m +++ b/Downloader.m @@ -128,12 +128,22 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas NSLog(@"RNFS download: unable to move tempfile to destination. %@, %@", error, error.userInfo); } + // When numerous downloads are called the sessions are not always invalidated and cleared by iOS14. + // This leads to error 28 – no space left on device so we manually flush and invalidate to free up space + if(session != nil){ + [session flushWithCompletitonHandler:^{ + [session finishTasksAndInvalidate]; + }]; + } + return _params.completeCallback(_statusCode, _bytesWritten); } - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - if (error && error.code != NSURLErrorCancelled) { + if (error) { + NSLog(@"RNFS download: didCompleteWithError %@, %@", error, error.userInfo); + if(error.code != NSURLErrorCancelled){ _resumeData = error.userInfo[NSURLSessionDownloadTaskResumeData]; if (_resumeData != nil) { if (_params.resumableCallback) { @@ -142,6 +152,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp } else { _params.errorCallback(error); } + } } }