Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ @interface OLPHttpClient ()<NSURLSessionDataDelegate>

@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;

Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
Loading