Skip to content

Commit 8ce8ddc

Browse files
Creation ios bg session under edicated ifdef (#1712)
There are concerns that bg session creation can take time. Related code is wrapped with OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD but not the session creation. Relates-To: MINOR Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent ac74097 commit 8ce8ddc

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ @interface OLPHttpClient ()<NSURLSessionDataDelegate>
7272

7373
@property(nonatomic, readonly) NSURLSession* sharedUrlSession;
7474

75+
#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
7576
@property(nonatomic, readonly) NSURLSession* sharedUrlBackgroundSession;
77+
#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
7678

7779
@property(nonatomic, readonly) NSMutableDictionary* idTaskMap;
7880

@@ -95,10 +97,14 @@ - (instancetype)init {
9597
_sharedUrlSession =
9698
[self urlSessionWithProxy:nil andHeaders:nil andBackgroundId:nil];
9799

100+
#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
101+
OLP_SDK_LOG_DEBUG(kLogTag, "Constructing shared background URL session");
102+
98103
_sharedUrlBackgroundSession =
99104
[self urlSessionWithProxy:nil
100105
andHeaders:nil
101106
andBackgroundId:[self generateNextSessionId]];
107+
#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
102108

103109
_tasks = [[NSMutableDictionary alloc] init];
104110
_idTaskMap = [[NSMutableDictionary alloc] init];
@@ -182,17 +188,23 @@ - (NSURLSessionTask*)createSessionTask:(NSURLSession*)session
182188
}
183189

184190
- (NSURLSession*)pickSession:(NSDictionary*)proxyDict {
185-
NSURLSession* session = _sharedUrlSession;
186-
191+
#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
187192
if (self.inBackground) {
188-
session = _sharedUrlBackgroundSession;
193+
NSURLSession* session = _sharedUrlBackgroundSession;
194+
195+
if (proxyDict) {
196+
session = [self urlSessionWithProxy:proxyDict
197+
andHeaders:nil
198+
andBackgroundId:[self generateNextSessionId]];
199+
}
200+
return session;
189201
}
202+
#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD
190203

204+
NSURLSession* session = _sharedUrlSession;
191205
if (proxyDict) {
192-
NSString* newSessionId = [self generateNextSessionId];
193-
session = [self urlSessionWithProxy:proxyDict
194-
andHeaders:nil
195-
andBackgroundId:newSessionId];
206+
session =
207+
[self urlSessionWithProxy:proxyDict andHeaders:nil andBackgroundId:nil];
196208
}
197209

198210
return session;

0 commit comments

Comments
 (0)