Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

MapboxGL Startup Infrastructure #1329

Merged
merged 10 commits into from
May 5, 2015
Merged

MapboxGL Startup Infrastructure #1329

merged 10 commits into from
May 5, 2015

Conversation

bleege
Copy link
Contributor

@bleege bleege commented Apr 22, 2015

For #1225

@bleege bleege added the iOS Mapbox Maps SDK for iOS label Apr 22, 2015
@bleege bleege added this to the iOS Beta 1 milestone Apr 22, 2015
if (accessToken) {
// Store to preferences so that we can launch the app later on without having to specify
// token.
[[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: A common strategy for user defaults keys is to make them match the names of the constants that define them. So you’d define a constant called MGLMapboxAccessTokenDefaultsKey with the value MGLMapboxAccessToken in MGLTypes.h and use that constant here. Obviously it doesn’t matter as long as you’re consistent, but it’s one less thing to worry about naming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd be better off putting things in a constant to avoid future potential problems with the @"access_token" magic string, too.

@bleege bleege self-assigned this Apr 29, 2015
@bleege
Copy link
Contributor Author

bleege commented May 4, 2015

@1ec5's feedback has been incorporated. The next step is to split MapboxGL.h back into a regular Umbrella Header file.

// Can be called from any thread. Called implicitly from any
// public class convenience methods.
//
+ (instancetype) sharedInstanceWithAccessToken:(NSString *)token {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method’s name is misleading. It implies that there can be more than one shared instance, that we’re mapping access tokens to shared instances somehow. What happens when this class begins to manage more than just an access token? +sharedInstanceWithUserName:accessToken:expiryDate:cachingPragma:?

I still think the two options in #1329 (comment) are the best ways forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly using the instance methods would then have the initial setup in the AppDelegate be something like:

[[MGLAcountManager sharedManager] setAccessToken:@"FOO"]

[MGLAcountManager sharedInstanceWithAccessToken:@"FOO"]

How about renaming it to managerWithInititalAccessTokenValue or a derivative?

FWIW, I'm not terribly fond of the C style option so I'd like to get the first option working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[MGLAcountManager sharedManager] setAccessToken:@"FOO"]

The way we do this in MBXMapKit is more brief:

[MGLAccountManager setAccessToken:]

Which is basically just a shortcut to the above, but doesn't require the user to worry about shared instances.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, +setAccessToken: could return an instancetype for easy access instead of void.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up implementing +setAccessToken that returned void instead of instancetype as the latter was causing crashes.

@bleege
Copy link
Contributor Author

bleege commented May 5, 2015

Ended up pulling the initial MGLMapboxEvents from the MGLAccountManager init block as the only way to create a MGLAccountManager now is via +setAccessToken.

bleege added a commit that referenced this pull request May 5, 2015
MapboxGL Startup Infrastructure
@bleege bleege merged commit acd27fc into master May 5, 2015
@bleege bleege deleted the 1225-start-token branch May 5, 2015 18:00
@@ -28,6 +28,7 @@
#import "SMCalloutView.h"

#import "MGLMapboxEvents.h"
#import "MapboxGL.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import statement likle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import statement likely makes some of the other ones redundant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants