diff options
author | Julian Rex <julian.rex@mapbox.com> | 2020-03-25 17:56:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 17:56:40 -0400 |
commit | 9009089a933013df93a35c095021a0c102f8788b (patch) | |
tree | c5ce48dd7b7eafb1b4bdef559ce1686da95070ee /platform/darwin/src/http_file_source.mm | |
parent | 0998ffbab8fee4a6e31a5293d239116dbe10449a (diff) | |
download | qtlocation-mapboxgl-9009089a933013df93a35c095021a0c102f8788b.tar.gz |
Add NSURLSession delegation to http_file_source.mm (#16321)
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 21 |
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; |