diff options
author | Julian Rex <julian.rex@gmail.com> | 2020-03-25 09:03:20 -0400 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-03-25 16:03:02 +0200 |
commit | c33fce49537ed1082886c193acfacf560ecb2626 (patch) | |
tree | 6c87836c6e7ba4de47ed30b6ceee3a952f1c2398 | |
parent | 9b88cc1633228d1b328d49eb0fed7bbb1b013776 (diff) | |
download | qtlocation-mapboxgl-upstream/jrex/urlsession-poc.tar.gz |
Ensure that session is kept alive till completion.upstream/jrex/urlsession-poc
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 5c4a9c1b82..1b5a67ea5d 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -250,7 +250,7 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, [MGLNativeNetworkManager.sharedManager startDownloadEvent:url.relativePath type:@"tile"]; } - NSURLSession *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. @@ -268,6 +268,8 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, request->task = [session dataTaskWithRequest:req completionHandler:^(NSData* data, NSURLResponse* res, NSError* error) { + session = nil; + if (error && [error code] == NSURLErrorCancelled) { [MGLNativeNetworkManager.sharedManager cancelDownloadEventForResponse:res]; return; |