-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Create Mapbox GL Start Infrastructure #1225
Comments
As you work on this, please keep in mind the XIB/storyboard scenario we enabled in #1070: it should still be possible to set an access token on a view-by-view basis, without overriding anything in the app delegate. Codeless setup is a compelling story (MapKit parity, makes for a good beginner’s guide, shorter demo GIFs), even if we expect most developers to go the programmatic route eventually. |
I'm not sure this is a good idea. A required singleton init method typically makes libraries harder to use.
What Mapbox services does Mapbox GL provide besides MapViews? |
Generally I agree, but in this particular case it's a very common iOS design pattern is to to initialize 3rd party code at app startup inside the app's - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Currently there are no other services besides MapViews, but if others were to come along in the future (ex: Directions API wrapper) the existing infrastructure would require developers to first create a MapView in order to get access tokens to use. This way would provide a service agnostic one line of code common setup. |
This is why any singleton setup step needs to be optional: individual top-level view classes like |
I think that we should hold off on this if the reason is possible future uses, but my understanding was that one might want to trigger metrics without necessary showing a map view at launch — or at all. For that we would need a singleton, and @bleege is right that this is common pattern. HockeyApp and other crash log services do this, as do other map libraries like Google for iOS:
|
Agree here as well, and services like directions and geocoding are probably better served using their own setters too, as |
Agreed. The goal isn't / wasn't to replace these (nor the ones in Directions and Geocoder), it was to provide a common area for the token to be set so that developers wouldn't have to set it in N number of places in their app as well as to allow Metrics to start without needing to display a MapView at launch. That said after now seeing the recent updates to MapboxDirections.swift and MapboxGeocoder.swift and how they're being used as separate Legos this isn't likely to be that onerous in the short term. Also Metrics is now started in This is a good discussion. Let's pull back on this idea for the time being and come back to it later if the need arrises. 👍 |
Isn't this still a problem though? If a map exists on a second tab, it won't be created until that tab is first shown, but metrics might be needed before then? I think we do need a singleton, but we just weren't talking about the right reasons above. Does that make sense? |
Yeah, the more I think about it this does sound like a distinct possibility. Metrics should be on an app wide basis where it's either on or it's off. I'm going to put this back on the |
…pDelegate and exposing MGLMapView.initWithFrame to support it
Continued work on this issue this afternoon. I was able to get the MapboxEvents stated inside the MapboxGL shared instance as well as halfway through @1ec5's code review suggestions. Big thanks to @1ec5 for that BTW.... super helpful for learning some of the finer points of Objective-C! Next up is to finish the other half of the recommendations. |
Happening in #1329 PR. |
…the singleton code into MGLAccountManager.h and .m
The current Mapbox GL startup system is all tied to
MGLMapView
. This means that in order for an app developer to use any Mapbox service a MapView has to be built. It also ties Metrics to MapView as well.Future State Goals
didFinishLaunchingWithOptions
[MapboxGL startWithAccessToken:@"YOURACCESSTOKENGOESHERE"];
MapboxGL startWithAccessToken
's responsibilities@mapbox/mobile
The text was updated successfully, but these errors were encountered: