Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually flush & invalidate completed session #972

Merged
merged 1 commit into from
Feb 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Downloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 flushWithCompletionHandler:^{
[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) {
Expand All @@ -142,6 +152,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp
} else {
_params.errorCallback(error);
}
}
}
}

Expand Down