This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MapboxGL Startup Infrastructure #1329
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
578d48b
#1225 - Initial setup of MapboxGL as a singleton object with access t…
bleege 19b5ef3
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into 1225…
bleege 7e14578
#1225 - Initial conversion of Mapbox GL app to set access token in Ap…
bleege 317be34
#1225 - Removing unavailable block on MGLMapView.initWithFrame
bleege 591c632
#1225 - Converting id to instancetype
bleege f960461
#1225 - Starting Mapbox Events at shared instance setup time
bleege 0e36bf1
#1225 - Restoring MapboxGL.h as an Umbrella header file by splitting …
bleege 7f6cc6c
#1225 - Renaming getAccessToken method to sharedAccessToken to avoid …
bleege 4ce4e97
Updating from master
bleege 804c092
#1225 - Simplifying MGLAccountManager for initial setup and access to…
bleege File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@interface MGLAccountManager : NSObject | ||
|
||
+ (void) setAccessToken:(NSString *) accessToken; | ||
+ (NSString *) accessToken; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
#import "MGLMapView.h" | ||
#import "MGLTypes.h" | ||
#import "MGLUserLocation.h" | ||
#import "MGLAccountManager.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#import "MGLAccountManager.h" | ||
#import "NSProcessInfo+MGLAdditions.h" | ||
#import "MGLMapboxEvents.h" | ||
|
||
@interface MGLAccountManager() | ||
|
||
@property (atomic) NSString *accessToken; | ||
|
||
@end | ||
|
||
|
||
@implementation MGLAccountManager | ||
|
||
static MGLAccountManager *_sharedManager; | ||
|
||
// Can be called from any thread. | ||
// | ||
+ (instancetype) sharedInstance { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { | ||
void (^setupBlock)() = ^{ | ||
_sharedManager = [[self alloc] init]; | ||
}; | ||
if ( ! [[NSThread currentThread] isMainThread]) { | ||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
setupBlock(); | ||
}); | ||
} | ||
else { | ||
setupBlock(); | ||
} | ||
} | ||
}); | ||
return _sharedManager; | ||
} | ||
|
||
+ (void) setAccessToken:(NSString *) accessToken { | ||
[[MGLAccountManager sharedInstance] setAccessToken:accessToken]; | ||
|
||
// Update MGLMapboxEvents | ||
// NOTE: This is (likely) the initial setup of MGLMapboxEvents | ||
[MGLMapboxEvents setToken:accessToken]; | ||
} | ||
|
||
+ (NSString *) accessToken { | ||
return [MGLAccountManager sharedInstance].accessToken; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#import "SMCalloutView.h" | ||
|
||
#import "MGLMapboxEvents.h" | ||
#import "MapboxGL.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import statement likle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import statement likely makes some of the other ones redundant. |
||
|
||
#import <algorithm> | ||
|
||
|
@@ -109,6 +110,7 @@ - (instancetype)initWithFrame:(CGRect)frame | |
if (self && [self commonInit]) | ||
{ | ||
self.styleURL = nil; | ||
self.accessToken = [MGLAccountManager accessToken]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the other direction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just ticketed it -> #1430 |
||
return self; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 valueMGLMapboxAccessToken
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.There was a problem hiding this comment.
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.