From 78baef8cf2b2f88be12c7edb45666bbba4298d0d Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Tue, 7 May 2019 16:35:17 +0200 Subject: [PATCH] Extract token from UserDefaults if applicable --- MapboxGeocoder/MBGeocoder.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MapboxGeocoder/MBGeocoder.swift b/MapboxGeocoder/MBGeocoder.swift index 1af05ad..fae0337 100644 --- a/MapboxGeocoder/MBGeocoder.swift +++ b/MapboxGeocoder/MBGeocoder.swift @@ -5,6 +5,8 @@ typealias JSONDictionary = [String: Any] /// Indicates that an error occurred in MapboxGeocoder. public let MBGeocoderErrorDomain = "MBGeocoderErrorDomain" +let MBXMapboxSKUTokenKey = "MBXMapboxSKUToken" + /// The Mapbox access token specified in the main application bundle’s Info.plist. let defaultAccessToken = Bundle.main.infoDictionary?["MGLMapboxAccessToken"] as? String @@ -328,9 +330,12 @@ open class Geocoder: NSObject { The HTTP URL used to fetch the geocodes from the API. */ @objc open func urlForGeocoding(_ options: GeocodeOptions) -> URL { - let params = options.params + [ - URLQueryItem(name: "access_token", value: accessToken), - ] + var params = options.params + params += [URLQueryItem(name: "access_token", value: accessToken)] + + if let skuToken = UserDefaults.standard.object(forKey: MBXMapboxSKUTokenKey) as? String { + params += [URLQueryItem(name: "sku", value: skuToken)] + } assert(!options.queries.isEmpty, "No query")