maplibre-native
maplibre-native copied to clipboard
iOS networking overrides
Greetings,
Do you have any plans on updating networking API in iOS SDK? Especially way to add additional headers / modify url for requests?
Right now in Android SDK you can provide a custom network routing via:
com.mapbox.mapboxsdk.module.http.HttpRequestUtil.setOkHttpClient(...)
In Web SDK you can provide a transformRequest
lambda to modify outgoing requests.
On both platforms overrides are per map instance.
On iOS only option is to provide a custom URLProtocol
and it's SDK wide, which is unreasonably complicated and inflexible.
Use case:
Our app provide multiple authentication options, such as: subscriptionKey
query parameter, Authorization
header, etc. Different map instances may use different options.
Multiple maps may exist at the same time.
Currently we required to:
- have global reference on all map instances
- determine from which map request comes based on
URLRequest
/ URL string
Having a way to modify requests before SDK would send them on per map basis would simplify a lot of things for us.
I think you could use MGLOfflineStorageDelegate
to modify URLs in your requests. For example, Amazon is using it to sign URLs.
Amazon Location does make use of the Offline storage delegate to perform its signing. See the iOS project aws-samples/amazon-location-samples:MapView.swift#L21,L25. Amazon Location specific signing is implemented in AWSSignatureV4Delegate, and is using MapLibre.
Thanks @petr-pokorny-1 for pointing out this usage of the Offline storage delegate.
Thanks, I would give it a try, but using offline delegate for online maps sounds counterintuitive. :D
If I understood it right, you need to:
- create class that conforms to
MGLOfflineStorageDelegate
- pass this instance into
MGLOfflineStorage.delegate
This solution solves most of issues with current URLProtocol
approach, except one: MGLOfflineStorage
is a singleton and this delegate is SDK wide.