Skip to content

Commit

Permalink
Delete cancelled and not valid background tasks (#1551)
Browse files Browse the repository at this point in the history
Foreground tasks are deleted in didCompleteWithError. Background tasks
are getting both didFinishDownloadingToURL and didCompleteWithError
events but the downloaded content is in the didFinishDownloadingToURL
only

Relates-To: DATASDK-45

Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
  • Loading branch information
rustam-gamidov-here authored Oct 8, 2024
1 parent de1463d commit a83f018
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,33 @@ - (void)URLSession:(NSURLSession*)session
@synchronized(_urlSessions) {
OLPHttpTask* httpTask =
[self taskWithTaskDescription:dataTask.taskDescription];

if (!httpTask) {
OLP_SDK_LOG_WARNING_F(kLogTag,
"didFinishDownloadingToURL failed - task can't "
"be found, session=%p, dataTask=%p, task_id=%u, "
"task_description=%s",
(__bridge void*)session, (__bridge void*)dataTask,
(unsigned int)dataTask.taskIdentifier,
(char*)[dataTask.taskDescription UTF8String]);
return;
}

if ([httpTask isValid] && ![httpTask isCancelled]) {
[httpTask didReceiveData:data withWholeData:true];
[httpTask didCompleteWithError:dataTask.error];
[self removeTaskWithId:httpTask.requestId];
} else {
OLP_SDK_LOG_WARNING_F(
kLogTag,
"didFinishDownloadingToURL failed - task can't be found or "
"cancelled, session=%p, dataTask=%p, task_id=%u",
"didFinishDownloadingToURL failed - task not valid or "
"cancelled, session=%p, dataTask=%p, task_id=%u, "
"task_description=%s",
(__bridge void*)session, (__bridge void*)dataTask,
(unsigned int)dataTask.taskIdentifier);
(unsigned int)dataTask.taskIdentifier,
(char*)[dataTask.taskDescription UTF8String]);
}

[self removeTaskWithId:httpTask.requestId];
}
}
}
Expand Down

0 comments on commit a83f018

Please sign in to comment.