Files
MapLibreParticleLab/platform/ios/MGLAccountManager.m
Minh Nguyễn 70381d2705 Fixed up various Info.plist edge cases
Need to look in the main bundle for Info.plist settings, because the developer has no access to the framework’s Info.plist. Need to check MGLMapboxMetricsEnabledSettingShownInApp before MGLMapboxAccessToken; otherwise, `MGLMapboxEvents` inspects the Settings bundle plist before MGLMapboxMetricsEnabledSettingShownInApp is even checked.
2015-05-21 01:49:53 -07:00

76 lines
2.2 KiB
Objective-C

#import <Foundation/Foundation.h>
#import "MGLAccountManager_Private.h"
#import "MGLMapboxEvents.h"
#import "NSProcessInfo+MGLAdditions.h"
@interface MGLAccountManager()
@property (atomic) BOOL mapboxMetricsEnabledSettingShownInApp;
@property (atomic) NSString *accessToken;
@end
@implementation MGLAccountManager
+ (void)load {
// Read the initial configuration from Info.plist. The shown-in-app setting
// preempts the Settings bundle check in -[MGLMapboxEvents init] triggered
// by setting the access token.
NSBundle *bundle = [NSBundle mainBundle];
NSNumber *shownInAppNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxMetricsEnabledSettingShownInApp"];
if (shownInAppNumber) {
[MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp = [shownInAppNumber boolValue];
}
self.accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
}
// Can be called from any thread.
//
+ (instancetype) sharedManager {
if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
return nil;
}
static dispatch_once_t onceToken;
static MGLAccountManager *_sharedManager;
void (^setupBlock)() = ^{
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});
};
if ( ! [[NSThread currentThread] isMainThread]) {
dispatch_sync(dispatch_get_main_queue(), ^{
setupBlock();
});
}
else {
setupBlock();
}
return _sharedManager;
}
+ (void) setMapboxMetricsEnabledSettingShownInApp:(BOOL)shown {
[MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp = shown;
}
+ (BOOL) mapboxMetricsEnabledSettingShownInApp {
return [MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp;
}
+ (void) setAccessToken:(NSString *) accessToken {
if ( ! [accessToken length]) return;
[MGLAccountManager sharedManager].accessToken = accessToken;
// Update MGLMapboxEvents
// NOTE: This is (likely) the initial setup of MGLMapboxEvents
[MGLMapboxEvents sharedManager];
}
+ (NSString *) accessToken {
return [MGLAccountManager sharedManager].accessToken;
}
@end