Skip to content

Commit 18b35de

Browse files
iOS to use NSURLSessionDownloadTask in background. (#1457)
This allows to continue data downloading when in background. Ongoing internal tasks are canceled. Timeouts should be set keeping in mind this mechanism is quite slow. Relates-To: OLPEDGE-2849 Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent 7c45d8e commit 18b35de

File tree

9 files changed

+401
-43
lines changed

9 files changed

+401
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ option(OLP_SDK_DISABLE_DEBUG_LOGGING "Disable debug and trace level logging" OFF
4545
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation based on LevelDB" ON)
4646
option(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB "Enable default cache implementation based on LMDB" OFF)
4747
option(OLP_SDK_ENABLE_ANDROID_CURL "Enable curl based network layer for Android" OFF)
48+
option(OLP_SDK_ENABLE_IOS_BACKGROUND_DOWNLOAD "Enable iOS network layer downloading in background. Under testing." OFF)
4849

4950
# C++ standard version. Minimum supported version is 11.
5051
set(CMAKE_CXX_STANDARD 11)

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ endif()
400400

401401
add_library(${PROJECT_NAME} ${OLP_SDK_CORE_SOURCES} ${OLP_SDK_CORE_HEADERS})
402402

403+
if (OLP_SDK_ENABLE_IOS_BACKGROUND_DOWNLOAD)
404+
target_compile_definitions(${PROJECT_NAME}
405+
PRIVATE OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD)
406+
endif()
407+
403408
if (OLP_SDK_DISABLE_DEBUG_LOGGING)
404409
target_compile_definitions(${PROJECT_NAME}
405410
PUBLIC LOGGING_DISABLE_DEBUG_LEVEL)

olp-cpp-sdk-core/src/http/ios/OLPHttpClient+Internal.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,9 @@
2121

2222
#import "OLPHttpClient.h"
2323

24+
#include <olp/core/http/NetworkProxySettings.h>
25+
#include <olp/core/http/NetworkTypes.h>
26+
2427
/**
2528
* @brief Internal category, which extends OLPHttpClient with internal methods,
2629
* which shouldn't be exposed as public API.
@@ -29,11 +32,22 @@
2932

3033
@property(nonatomic, readonly) NSArray* activeTasks;
3134

32-
- (NSURLSession*)urlSessionWithProxy:
33-
(const olp::http::NetworkProxySettings&)proxySettings
34-
andHeaders:(NSDictionary*)headers;
35+
- (NSMutableDictionary*)toProxyDict:
36+
(const olp::http::NetworkProxySettings&)proxySettings;
37+
38+
- (NSURLSession*)urlSessionWithProxy:(NSDictionary*)proxyDict
39+
andHeaders:(NSDictionary*)headers
40+
andBackgroundId:(NSString*)sessionBackgroundId;
41+
42+
- (NSURLSession*)pickSession:(NSDictionary*)proxyDict;
3543

36-
- (void)registerDataTask:(NSURLSessionDataTask*)dataTask
44+
- (void)registerDataTask:(NSURLSessionTask*)dataTask
3745
forHttpTask:(OLPHttpTask*)httpTask;
3846

47+
- (NSURLSessionTask*)createSessionTask:(NSURLSession*)session
48+
withRequest:(NSMutableURLRequest*)request
49+
withBackgroundMode:(bool)backgroundMode;
50+
51+
- (void)restartCurrentTasks;
52+
3953
@end

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,10 @@ class NetworkProxySettings;
3636
*/
3737
@interface OLPHttpClient : NSObject
3838

39+
@property(nonatomic) NSMutableDictionary *toIgnoreResponse;
40+
41+
@property(nonatomic) bool inBackground;
42+
3943
/// Creates a task with specific identifier with corresponding settings
4044
- (OLPHttpTask *)createTaskWithProxy:
4145
(const olp::http::NetworkProxySettings &)proxySettings

0 commit comments

Comments
 (0)