diff options
author | Julian Rex <julian.rex@gmail.com> | 2018-11-21 13:56:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-21 13:56:41 -0500 |
commit | fd4b4701587c90271978b5f24d9a9355989182e0 (patch) | |
tree | 676ad30cd48e87b3aa53aceab3cfd5973ce82a38 /platform/darwin/src/MGLRendererConfiguration.mm | |
parent | 7d5be980e287c979119b06c73d071f2daaea1b3d (diff) | |
download | qtlocation-mapboxgl-fd4b4701587c90271978b5f24d9a9355989182e0.tar.gz |
[ios] Adds support for MGLCollisionBehaviorPre4_0 in NSUserDefaults (#13426)
Diffstat (limited to 'platform/darwin/src/MGLRendererConfiguration.mm')
-rw-r--r-- | platform/darwin/src/MGLRendererConfiguration.mm | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm index b31da674cf..90778ea86d 100644 --- a/platform/darwin/src/MGLRendererConfiguration.mm +++ b/platform/darwin/src/MGLRendererConfiguration.mm @@ -1,5 +1,6 @@ #import "MGLRendererConfiguration.h" #import "MGLOfflineStorage_Private.h" +#import "MGLFoundation_Private.h" #if TARGET_OS_IPHONE #import <UIKit/UIKit.h> @@ -7,6 +8,12 @@ #import <AppKit/AppKit.h> #endif +static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPre4_0"; + +@interface MGLRendererConfiguration () +@property (nonatomic, readwrite) BOOL perSourceCollisions; +@end + @implementation MGLRendererConfiguration @@ -14,6 +21,42 @@ return [[self alloc] init]; } +- (instancetype)init { + return [self initWithPropertyDictionary:[[NSBundle mainBundle] infoDictionary]]; +} + +- (instancetype)initWithPropertyDictionary:(nonnull NSDictionary *)properties { + self = [super init]; + + if (self) { + // Set the collision behaviour. A value set in `NSUserDefaults.standardUserDefaults` + // should override anything in the application's info.plist + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ([defaults objectForKey:MGLCollisionBehaviorPre4_0Key]) { + _perSourceCollisions = [defaults boolForKey:MGLCollisionBehaviorPre4_0Key]; + } + else { + id collisionBehaviourValue = properties[MGLCollisionBehaviorPre4_0Key]; + + NSNumber *collisionBehaviourNumber = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSNumber); + + if (collisionBehaviourNumber) { + _perSourceCollisions = collisionBehaviourNumber.boolValue; + } else { + // Also support NSString to correspond with the behavior of `-[NSUserDefaults boolForKey:]` + NSString *collisionBehaviourString = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSString); + + if (collisionBehaviourString) { + _perSourceCollisions = collisionBehaviourString.boolValue; + } + } + } + } + + return self; +} + - (mbgl::DefaultFileSource *)fileSource { return [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; } @@ -40,10 +83,4 @@ return fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>(); } -- (BOOL)perSourceCollisions { - NSNumber *boolWrapper = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"MGLCollisionBehaviorPre4_0"]; - - return boolWrapper.boolValue; -} - @end |