diff options
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index c26568d8bc..29f8f7db68 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -7,9 +7,14 @@ #include <mbgl/util/version.hpp> #import <Foundation/Foundation.h> + #import "MGLLoggingConfiguration_Private.h" #import "MGLNetworkConfiguration_Private.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MGLAccountManager_Private.h" +#endif + #include <mutex> #include <chrono> @@ -196,16 +201,25 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, auto shared = request->shared; // Explicit copy so that it also gets copied into the completion handler block below. @autoreleasepool { - NSURL* url = [NSURL URLWithString:@(resource.url.c_str())]; + NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; MGLLogDebug(@"Requesting URI: %@", url.relativePath); + +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR if (impl->accountType == 0 && ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) { - NSString* absoluteString = [url.absoluteString - stringByAppendingFormat:(url.query ? @"&%@" : @"?%@"), @"events=true"]; - url = [NSURL URLWithString:absoluteString]; + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + NSArray *newQueryItems = @[ + [NSURLQueryItem queryItemWithName:@"events" value:@"true"], + [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken] + ]; + + components.queryItems = components.queryItems ? [components.queryItems arrayByAddingObjectsFromArray:newQueryItems] : newQueryItems; + + url = components.URL; } +#endif - NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url]; + NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; if (resource.priorEtag) { [req addValue:@(resource.priorEtag->c_str()) forHTTPHeaderField:@"If-None-Match"]; |