Skip to content

Commit a83f018

Browse files
Delete cancelled and not valid background tasks (#1551)
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>
1 parent de1463d commit a83f018

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,33 @@ - (void)URLSession:(NSURLSession*)session
562562
@synchronized(_urlSessions) {
563563
OLPHttpTask* httpTask =
564564
[self taskWithTaskDescription:dataTask.taskDescription];
565+
566+
if (!httpTask) {
567+
OLP_SDK_LOG_WARNING_F(kLogTag,
568+
"didFinishDownloadingToURL failed - task can't "
569+
"be found, session=%p, dataTask=%p, task_id=%u, "
570+
"task_description=%s",
571+
(__bridge void*)session, (__bridge void*)dataTask,
572+
(unsigned int)dataTask.taskIdentifier,
573+
(char*)[dataTask.taskDescription UTF8String]);
574+
return;
575+
}
576+
565577
if ([httpTask isValid] && ![httpTask isCancelled]) {
566578
[httpTask didReceiveData:data withWholeData:true];
567579
[httpTask didCompleteWithError:dataTask.error];
568-
[self removeTaskWithId:httpTask.requestId];
569580
} else {
570581
OLP_SDK_LOG_WARNING_F(
571582
kLogTag,
572-
"didFinishDownloadingToURL failed - task can't be found or "
573-
"cancelled, session=%p, dataTask=%p, task_id=%u",
583+
"didFinishDownloadingToURL failed - task not valid or "
584+
"cancelled, session=%p, dataTask=%p, task_id=%u, "
585+
"task_description=%s",
574586
(__bridge void*)session, (__bridge void*)dataTask,
575-
(unsigned int)dataTask.taskIdentifier);
587+
(unsigned int)dataTask.taskIdentifier,
588+
(char*)[dataTask.taskDescription UTF8String]);
576589
}
590+
591+
[self removeTaskWithId:httpTask.requestId];
577592
}
578593
}
579594
}

0 commit comments

Comments
 (0)