Files
MapLibreParticleLab/platform/darwin/src/MGLAccountManager.m
Minh Nguyễn 7a38e56819 [ios] Removed alternative to -ObjC
Xcode’s static library template comes with the -ObjC linker flag by default. Instead of removing that flag, this change removes the various imperfect workarounds we’ve been using to ensure that private SDK categories link. Given the size decrease in this static library since #2966 was fixed, we should have room to spare for the more straightforward approach. Moreover, an application that uses MGLMapView in a storyboard no longer needs to add -ObjC to the application target, which bloated the entire application, including other frameworks that had no need for -ObjC.

-ObjC isn’t even needed for dynamic frameworks, and the OS X SDK is only built as a dynamic framework.
2016-04-16 22:46:23 -07:00

114 lines
3.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#import "MGLAccountManager_Private.h"
#import "NSBundle+MGLAdditions.h"
#import "NSProcessInfo+MGLAdditions.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MGLMapboxEvents.h"
#import "FABKitProtocol.h"
#import "Fabric+FABKits.h"
@interface MGLAccountManager () <FABKit>
@property (atomic) NSString *accessToken;
@end
#else
@interface MGLAccountManager ()
@property (atomic) NSString *accessToken;
@end
#endif
@implementation MGLAccountManager
#pragma mark - Internal
+ (void)load {
// Read the initial configuration from Info.plist.
NSString *accessToken = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
if (accessToken.length) {
self.accessToken = accessToken;
}
}
+ (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;
}
+ (BOOL)mapboxMetricsEnabledSettingShownInApp {
NSLog(@"mapboxMetricsEnabledSettingShownInApp is no longer necessary; the Mapbox iOS SDK has changed to always provide a telemetry setting in-app.");
return YES;
}
+ (void)setAccessToken:(NSString *)accessToken {
accessToken = [accessToken stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (!accessToken.length) {
return;
}
[MGLAccountManager sharedManager].accessToken = accessToken;
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
// Update MGLMapboxEvents
// NOTE: This is (likely) the initial setup of MGLMapboxEvents
[MGLMapboxEvents sharedManager];
#endif
}
+ (NSString *)accessToken {
return [MGLAccountManager sharedManager].accessToken;
}
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#pragma mark - Fabric
+ (NSString *)bundleIdentifier {
return [NSBundle mgl_frameworkBundleIdentifier];
}
+ (NSString *)kitDisplayVersion {
return [NSBundle mgl_frameworkInfoDictionary][@"CFBundleShortVersionString"];
}
+ (void)initializeIfNeeded {
Class fabric = NSClassFromString(@"Fabric");
if (fabric) {
NSDictionary *configuration = [fabric configurationDictionaryForKitClass:[MGLAccountManager class]];
if (!configuration || !configuration[@"accessToken"]) {
NSLog(@"Configuration dictionary returned by Fabric was nil or doesn’t have accessToken. Can’t initialize MGLAccountManager.");
return;
}
[self setAccessToken:configuration[@"accessToken"]];
MGLAccountManager *sharedAccountManager = [self sharedManager];
NSLog(@"MGLAccountManager was initialized with access token: %@", sharedAccountManager.accessToken);
} else {
NSLog(@"MGLAccountManager is used in a project that doesn’t have Fabric.");
}
}
#endif
@end