Grab access token and other app-wide data from Info.plist
That way there’s no ambiguity about when you should call things like `+[MGLAccountManager setMapboxMetricsEnabledSettingShownInApp:]`. In fact, that method is now deprecated because it’s so easy to call in the wrong place. Fixes #1535.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
/** Certain Mapbox plans require the collection of user metrics. If you aren't using a preference switch in an existing or new `Settings.bundle` in your application, set this value to `YES` to indicate that you are providing a metrics opt-out for users within your app's interface directly.
|
||||
* @param showsOptOut Whether your application's interface provides a user opt-out preference. The default value is `NO`, meaning a `Settings.bundle` is expected for providing a user opt-out preference. */
|
||||
+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;
|
||||
+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut DEPRECATED_MSG_ATTRIBUTE("Set MGLMapboxMetricsEnabledSettingShownInApp in Info.plist");
|
||||
|
||||
/** Whether in-app user metrics opt-out is configured. If set to the default value of `NO`, a user opt-out preference is expected in a `Settings.bundle` that shows in the application's section within the system Settings app. */
|
||||
+ (BOOL)mapboxMetricsEnabledSettingShownInApp;
|
||||
|
||||
@@ -9,11 +9,25 @@
|
||||
@property (atomic) BOOL mapboxMetricsEnabledSettingShownInApp;
|
||||
@property (atomic) NSString *accessToken;
|
||||
|
||||
+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation MGLAccountManager
|
||||
|
||||
+ (void)initialize {
|
||||
if (self == [MGLAccountManager class]) {
|
||||
// Read initial configuration from Info.plist.
|
||||
NSBundle *bundle = [NSBundle bundleForClass:self];
|
||||
self.accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
|
||||
NSNumber *shownInAppNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxMetricsEnabledSettingShownInApp"];
|
||||
if (shownInAppNumber) {
|
||||
[MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp = [shownInAppNumber boolValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Can be called from any thread.
|
||||
//
|
||||
+ (instancetype) sharedManager {
|
||||
@@ -25,7 +39,6 @@
|
||||
void (^setupBlock)() = ^{
|
||||
dispatch_once(&onceToken, ^{
|
||||
_sharedManager = [[self alloc] init];
|
||||
_sharedManager.mapboxMetricsEnabledSettingShownInApp = NO;
|
||||
});
|
||||
};
|
||||
if ( ! [[NSThread currentThread] isMainThread]) {
|
||||
@@ -48,6 +61,8 @@
|
||||
}
|
||||
|
||||
+ (void) setAccessToken:(NSString *) accessToken {
|
||||
if ( ! [accessToken length]) return;
|
||||
|
||||
[[MGLAccountManager sharedManager] setAccessToken:accessToken];
|
||||
|
||||
// Update MGLMapboxEvents
|
||||
|
||||
@@ -176,8 +176,10 @@ const NSTimeInterval MGLFlushInterval = 60;
|
||||
|
||||
+ (void)initialize {
|
||||
if (self == [MGLMapboxEvents class]) {
|
||||
NSBundle *bundle = [NSBundle bundleForClass:self];
|
||||
NSNumber *accountTypeNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccountType"];
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
|
||||
@"MGLMapboxAccountType": @0,
|
||||
@"MGLMapboxAccountType": accountTypeNumber ? accountTypeNumber : @0,
|
||||
@"MGLMapboxMetricsEnabled": @YES,
|
||||
}];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user