summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLAccountManager.m
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-05 18:00:11 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-03-10 17:08:58 -0800
commite36218a8668316e8c1b0bcc06d43dad31461615c (patch)
tree04d5e58ae0c4dea4b0a50e034a8a630564cb7a53 /platform/darwin/src/MGLAccountManager.m
parent081ee9fbefbdb37f116a5bf2c0383586bce6608a (diff)
downloadqtlocation-mapboxgl-e36218a8668316e8c1b0bcc06d43dad31461615c.tar.gz
[osx] Added OS X support for offline downloads
Diffstat (limited to 'platform/darwin/src/MGLAccountManager.m')
-rw-r--r--platform/darwin/src/MGLAccountManager.m123
1 files changed, 123 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m
new file mode 100644
index 0000000000..bfaf9faae9
--- /dev/null
+++ b/platform/darwin/src/MGLAccountManager.m
@@ -0,0 +1,123 @@
+#import "MGLAccountManager_Private.h"
+#import "MGLMapView.h"
+#import "NSBundle+MGLAdditions.h"
+#import "NSProcessInfo+MGLAdditions.h"
+#import "NSString+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.");
+ }
+
+ // https://github.com/mapbox/mapbox-gl-native/issues/2966
+ mgl_linkBundleCategory();
+ mgl_linkStringCategory();
+ mgl_linkProcessInfoCategory();
+
+ // https://github.com/mapbox/mapbox-gl-native/issues/3113
+ [MGLMapView class];
+}
+
+#endif
+
+@end