This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit renames MGLAccountManager to MGLConfigurationManager since the name "account" was too specific. In addition, a new setting was added to the configuration manager to allow a user to specify a desired `activityType` to be used by location manager instances in the library. This was added using existing conventions so that the value can be specified by the API or in the Info.plist in the client application. It's worth noting that, for backwards compatibility reasons, MGLAccountManager was kept around with deprecation warnings and just serves as a wrapper for MGLConfigurationManager. Finally, a few unrelated changes were made to clean up an unused property in the MGLConfigurationManager_Private header and to make constants for string values used in MGLConfigurationManager (what was MGLAccountManager).
- Loading branch information
Showing
12 changed files
with
209 additions
and
103 deletions.
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
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,43 @@ | ||
#import "MGLTypes.h" | ||
#import <CoreLocation/CoreLocation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** The MGLConfigurationManager object provides a global way to set a Mapbox API access token, as well as other settings used framework-wide. */ | ||
@interface MGLConfigurationManager : NSObject | ||
|
||
/** @name Authorizing Access */ | ||
|
||
/** Set the Mapbox API access token for the framework. | ||
* | ||
* You can set an access token on MGLConfigurationManager or on an individual map view. The same token is used throughout the framework. | ||
* @param accessToken The Mapbox API access token. */ | ||
+ (void)setAccessToken:(nullable NSString *)accessToken; | ||
|
||
/** Retreive the Mapbox API access token for the framework. | ||
* | ||
* You can set an access token on MGLConfigurationManager or on an individual map view. The same token is used throughout the framework. | ||
* @return accessToken The Mapbox API access token. */ | ||
+ (nullable NSString *)accessToken; | ||
|
||
/** @name Providing User Metrics Opt-Out */ | ||
+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut __attribute__((unavailable("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; | ||
|
||
/** Set the type of activity associated with location updates for the application. | ||
* | ||
* You can configure the activity type associated with location updates that make the most sense for youre application. | ||
* @param activityType The desired CLActivityType */ | ||
+ (void)setActivityType:(CLActivityType)activityType; | ||
|
||
/** Retreive the type of activity associated with location updates for the application. | ||
* | ||
* You can configure the activity type associated with location updates that make the most sense for your application. | ||
* @return activityType The configured CLActivityType*/ | ||
+ (CLActivityType)activityType; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_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
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 |
---|---|---|
@@ -1,73 +1,18 @@ | ||
#import "MGLAccountManager_Private.h" | ||
#import "MGLMapboxEvents.h" | ||
#import "NSProcessInfo+MGLAdditions.h" | ||
|
||
@interface MGLAccountManager() | ||
|
||
@property (atomic) BOOL mapboxMetricsEnabledSettingShownInApp; | ||
@property (atomic) NSString *accessToken; | ||
|
||
@end | ||
|
||
#import "MGLAccountManager.h" | ||
#import "MGLConfigurationManager.h" | ||
|
||
@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]; | ||
} | ||
NSString *accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"]; | ||
if (accessToken.length) { | ||
self.accessToken = accessToken; | ||
} | ||
} | ||
|
||
// 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)setAccessToken:(nullable NSString *)accessToken { | ||
[MGLConfigurationManager setAccessToken:accessToken]; | ||
} | ||
|
||
+ (BOOL) mapboxMetricsEnabledSettingShownInApp { | ||
return [MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp; | ||
+ (nullable NSString *)accessToken { | ||
return [MGLConfigurationManager accessToken]; | ||
} | ||
|
||
+ (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]; | ||
+ (BOOL)mapboxMetricsEnabledSettingShownInApp { | ||
return [MGLConfigurationManager mapboxMetricsEnabledSettingShownInApp]; | ||
} | ||
|
||
+ (NSString *) accessToken { | ||
return [MGLAccountManager sharedManager].accessToken; | ||
} | ||
|
||
|
||
@end |
This file was deleted.
Oops, something went wrong.
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,117 @@ | ||
#import "MGLConfigurationManager_Private.h" | ||
#import "MGLMapboxEvents.h" | ||
#import "NSProcessInfo+MGLAdditions.h" | ||
|
||
static NSString * const kMGLMapboxMetricsEnabledSettingShownInApp = @"MGLMapboxMetricsEnabledSettingShownInApp"; | ||
static NSString * const kMGLMapboxAccessToken = @"MGLMapboxAccessToken"; | ||
static NSString * const kMGLMapboxActivityType = @"MGLMapboxActivityType"; | ||
|
||
// Used for parsing options specified in info.plist | ||
static NSString * const kMGLMapboxActivityTypeOther = @"Other"; | ||
static NSString * const kMGLMapboxActivityTypeAutomotiveNavigation = @"AutomotiveNavigation"; | ||
static NSString * const kMGLMapboxActivityTypeFitness = @"Fitness"; | ||
static NSString * const kMGLMapboxActivityTypeOtherNavigation = @"OtherNavigation"; | ||
|
||
@interface MGLConfigurationManager () | ||
|
||
@property (atomic) BOOL mapboxMetricsEnabledSettingShownInApp; | ||
@property (atomic) NSString *accessToken; | ||
@property (atomic) CLActivityType activityType; | ||
|
||
@end | ||
|
||
|
||
@implementation MGLConfigurationManager | ||
|
||
+ (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:kMGLMapboxMetricsEnabledSettingShownInApp]; | ||
if (shownInAppNumber) { | ||
[MGLConfigurationManager sharedManager].mapboxMetricsEnabledSettingShownInApp = [shownInAppNumber boolValue]; | ||
} | ||
|
||
NSString *accessToken = [bundle objectForInfoDictionaryKey:kMGLMapboxAccessToken]; | ||
if (accessToken.length) { | ||
self.accessToken = accessToken; | ||
} | ||
|
||
NSString *activityType = [bundle objectForInfoDictionaryKey:kMGLMapboxActivityType]; | ||
if (activityType.length) { | ||
self.activityType = [self activityTypeForBundleStringValue:activityType]; | ||
} | ||
} | ||
|
||
// Can be called from any thread. | ||
// | ||
+ (instancetype) sharedManager { | ||
if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { | ||
return nil; | ||
} | ||
static dispatch_once_t onceToken; | ||
static MGLConfigurationManager *_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 { | ||
return [MGLConfigurationManager sharedManager].mapboxMetricsEnabledSettingShownInApp; | ||
} | ||
|
||
+ (void) setAccessToken:(NSString *) accessToken { | ||
if ( ! [accessToken length]) return; | ||
|
||
[MGLConfigurationManager sharedManager].accessToken = accessToken; | ||
|
||
// Update MGLMapboxEvents | ||
// NOTE: This is (likely) the initial setup of MGLMapboxEvents | ||
[MGLMapboxEvents sharedManager]; | ||
} | ||
|
||
+ (NSString *) accessToken { | ||
return [MGLConfigurationManager sharedManager].accessToken; | ||
} | ||
|
||
+ (void) setActivityType:(CLActivityType)activityType { | ||
[MGLConfigurationManager sharedManager].activityType = activityType; | ||
|
||
// Ensure MGLMapboxEvents configures location manager with new activity type | ||
[MGLMapboxEvents validate]; | ||
} | ||
|
||
+ (CLActivityType) activityType { | ||
return [MGLConfigurationManager sharedManager].activityType; | ||
} | ||
|
||
#pragma mark - Utility | ||
|
||
+ (CLActivityType)activityTypeForBundleStringValue:(NSString *)stringValue { | ||
if ([stringValue isEqualToString:kMGLMapboxActivityTypeAutomotiveNavigation]) { | ||
return CLActivityTypeAutomotiveNavigation; | ||
} | ||
if ([stringValue isEqual:kMGLMapboxActivityTypeFitness]) { | ||
return CLActivityTypeFitness; | ||
} | ||
if ([stringValue isEqual:kMGLMapboxActivityTypeOtherNavigation]) { | ||
return CLActivityTypeOtherNavigation; | ||
} | ||
return CLActivityTypeOther; | ||
} | ||
|
||
|
||
@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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import "MGLConfigurationManager.h" | ||
|
||
@interface MGLConfigurationManager (Private) | ||
|
||
/** Returns the shared instance of the `MGLConfigurationManager` class. */ | ||
+ (instancetype)sharedManager; | ||
|
||
@end |
Oops, something went wrong.