From af4d7eec8fa78820a4b8a4cf949380874c1b0fed Mon Sep 17 00:00:00 2001 From: Rustam Gamidov Date: Mon, 13 Jul 2026 09:19:44 +0300 Subject: [PATCH] Creation ios bg session under edicated ifdef 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 --- .../src/http/ios/OLPHttpClient.mm | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm index 9388eaafe..bf91b78f4 100644 --- a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm +++ b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm @@ -72,7 +72,9 @@ @interface OLPHttpClient () @property(nonatomic, readonly) NSURLSession* sharedUrlSession; +#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD @property(nonatomic, readonly) NSURLSession* sharedUrlBackgroundSession; +#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD @property(nonatomic, readonly) NSMutableDictionary* idTaskMap; @@ -95,10 +97,14 @@ - (instancetype)init { _sharedUrlSession = [self urlSessionWithProxy:nil andHeaders:nil andBackgroundId:nil]; +#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD + OLP_SDK_LOG_DEBUG(kLogTag, "Constructing shared background URL session"); + _sharedUrlBackgroundSession = [self urlSessionWithProxy:nil andHeaders:nil andBackgroundId:[self generateNextSessionId]]; +#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD _tasks = [[NSMutableDictionary alloc] init]; _idTaskMap = [[NSMutableDictionary alloc] init]; @@ -182,17 +188,23 @@ - (NSURLSessionTask*)createSessionTask:(NSURLSession*)session } - (NSURLSession*)pickSession:(NSDictionary*)proxyDict { - NSURLSession* session = _sharedUrlSession; - +#ifdef OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD if (self.inBackground) { - session = _sharedUrlBackgroundSession; + NSURLSession* session = _sharedUrlBackgroundSession; + + if (proxyDict) { + session = [self urlSessionWithProxy:proxyDict + andHeaders:nil + andBackgroundId:[self generateNextSessionId]]; + } + return session; } +#endif // OLP_SDK_NETWORK_IOS_BACKGROUND_DOWNLOAD + NSURLSession* session = _sharedUrlSession; if (proxyDict) { - NSString* newSessionId = [self generateNextSessionId]; - session = [self urlSessionWithProxy:proxyDict - andHeaders:nil - andBackgroundId:newSessionId]; + session = + [self urlSessionWithProxy:proxyDict andHeaders:nil andBackgroundId:nil]; } return session;