summaryrefslogtreecommitdiff
path: root/platform/darwin/src/http_file_source.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r--platform/darwin/src/http_file_source.mm21
1 files changed, 19 insertions, 2 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm
index a72a97e299..1b5a67ea5d 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -249,10 +249,27 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
if (isTile) {
[MGLNativeNetworkManager.sharedManager startDownloadEvent:url.relativePath type:@"tile"];
}
-
- request->task = [impl->session
+
+ __block NSURLSession *session;
+
+ // Use the delegate's session if there is one, otherwise use the one that
+ // was created when this class was constructed.
+ MGLNativeNetworkManager *networkManager = MGLNativeNetworkManager.sharedManager;
+ if ([networkManager.delegate respondsToSelector:@selector(sessionForNetworkManager:)]) {
+ session = [networkManager.delegate sessionForNetworkManager:networkManager];
+ }
+
+ if (!session) {
+ session = impl->session;
+ }
+
+ assert(session);
+
+ request->task = [session
dataTaskWithRequest:req
completionHandler:^(NSData* data, NSURLResponse* res, NSError* error) {
+ session = nil;
+
if (error && [error code] == NSURLErrorCancelled) {
[MGLNativeNetworkManager.sharedManager cancelDownloadEventForResponse:res];
return;