summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-01-17 09:41:37 -0500
committerFabian Guerra <fabian.guerra@mapbox.com>2018-01-17 09:41:37 -0500
commit42bcb4b405a4bdc344c6c3d260cf4521e05943cc (patch)
treeebb421afca52b149677e34fa94b9a08292ede184 /platform/ios
parent69ac7b6922c8b92fbc9beafae3a222703d4fe826 (diff)
parent2411fb31b70fde6a076886390abdaedde86ea2e5 (diff)
downloadqtlocation-mapboxgl-42bcb4b405a4bdc344c6c3d260cf4521e05943cc.tar.gz
Merge branch 'release-agua' into master
# Conflicts: # platform/android/CHANGELOG.md # platform/android/MapboxGLAndroidSDK/gradle.properties # platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java # platform/ios/CHANGELOG.md # platform/ios/ios.xcodeproj/project.pbxproj # platform/macos/CHANGELOG.md
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/CHANGELOG.md6
-rw-r--r--platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec2
-rw-r--r--platform/ios/Mapbox-iOS-SDK-symbols.podspec2
-rw-r--r--platform/ios/Mapbox-iOS-SDK.podspec2
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj4
-rw-r--r--platform/ios/src/MGLMapView.mm56
-rw-r--r--platform/ios/src/MGLMapboxEvents.m103
-rw-r--r--platform/ios/test/MGLMapViewLayoutTests.m108
8 files changed, 212 insertions, 71 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index d83b4890c2..e1e142fc14 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -21,6 +21,12 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Long-pressing the attribution button causes the SDK’s version number to be displayed in the action sheet that appears. ([#10650](https://github.com/mapbox/mapbox-gl-native/pull/10650))
+## 3.7.3
+
+* Fixed a crash while zooming while annotations are present on the map. ([#10791](https://github.com/mapbox/mapbox-gl-native/pull/10791))
+* CJK characters can be displayed in a locally installed font or a custom font bundled with the application, reducing map download times. Specify the font name using the `MGLIdeographicFontFamilyName` key in the application’s Info.plist file. ([#10522](https://github.com/mapbox/mapbox-gl-native/pull/10522))
+* Fixed a hang that could occur if the application makes many changes to user defaults immediately after launching. ([#10803](https://github.com/mapbox/mapbox-gl-native/pull/10803))
+
## 3.7.2 - December 21, 2017
### Packaging
diff --git a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec
index 5a1f1ebb7e..fb9511e707 100644
--- a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec
+++ b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |m|
- version = '3.7.2'
+ version = '3.7.3'
m.name = 'Mapbox-iOS-SDK-nightly-dynamic'
m.version = "#{version}-nightly"
diff --git a/platform/ios/Mapbox-iOS-SDK-symbols.podspec b/platform/ios/Mapbox-iOS-SDK-symbols.podspec
index 00b9437338..ea8ae667f6 100644
--- a/platform/ios/Mapbox-iOS-SDK-symbols.podspec
+++ b/platform/ios/Mapbox-iOS-SDK-symbols.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |m|
- version = '3.7.2'
+ version = '3.7.3'
m.name = 'Mapbox-iOS-SDK-symbols'
m.version = "#{version}-symbols"
diff --git a/platform/ios/Mapbox-iOS-SDK.podspec b/platform/ios/Mapbox-iOS-SDK.podspec
index 2f2a19300c..1e81272d6d 100644
--- a/platform/ios/Mapbox-iOS-SDK.podspec
+++ b/platform/ios/Mapbox-iOS-SDK.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |m|
- version = '3.7.2'
+ version = '3.7.3'
m.name = 'Mapbox-iOS-SDK'
m.version = version
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index fb268fab1d..cfb133f1cb 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -14,6 +14,7 @@
071BBB071EE77631001FB02A /* MGLImageSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 071BBB051EE7761A001FB02A /* MGLImageSourceTests.m */; };
0778DD431F67556700A73B34 /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 0778DD401F67555F00A73B34 /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
0778DD441F67556C00A73B34 /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0778DD411F67555F00A73B34 /* MGLComputedShapeSource.mm */; };
+ 16376B491FFEED010000563E /* MGLMapViewLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16376B481FFEED010000563E /* MGLMapViewLayoutTests.m */; };
07D8C6FB1F67560100381808 /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0778DD411F67555F00A73B34 /* MGLComputedShapeSource.mm */; };
07D8C6FC1F67560400381808 /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07D947501F67487E00E37934 /* MGLAbstractShapeSource.mm */; };
07D8C6FF1F67562C00381808 /* MGLComputedShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 07D8C6FD1F67562800381808 /* MGLComputedShapeSourceTests.m */; };
@@ -627,6 +628,7 @@
0778DD401F67555F00A73B34 /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = "<group>"; };
0778DD411F67555F00A73B34 /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = "<group>"; };
07D8C6FD1F67562800381808 /* MGLComputedShapeSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLComputedShapeSourceTests.m; path = ../../darwin/test/MGLComputedShapeSourceTests.m; sourceTree = "<group>"; };
+ 16376B481FFEED010000563E /* MGLMapViewLayoutTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewLayoutTests.m; sourceTree = "<group>"; };
07D9474E1F67487E00E37934 /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = "<group>"; };
07D9474F1F67487E00E37934 /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = "<group>"; };
07D947501F67487E00E37934 /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = "<group>"; };
@@ -1420,6 +1422,7 @@
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */,
DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */,
DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */,
+ 16376B481FFEED010000563E /* MGLMapViewLayoutTests.m */,
35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */,
1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */,
DAE7DEC11E245455007505A6 /* MGLNSStringAdditionsTests.m */,
@@ -2409,6 +2412,7 @@
DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */,
556660D81E1D085500E2C41B /* MGLVersionNumber.m in Sources */,
4031ACFF1E9FD29F00A3EA26 /* MGLSDKTestHelpers.swift in Sources */,
+ 16376B491FFEED010000563E /* MGLMapViewLayoutTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 33bbefc9db..31eac056e5 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -757,7 +757,7 @@ public:
toItem:viewController.topLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1.0
- constant:5.0]];
+ constant:8.0]];
}
[self.compassViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:self.compassView
@@ -766,7 +766,7 @@ public:
toItem:self
attribute:NSLayoutAttributeTop
multiplier:1.0
- constant:5.0 + self.contentInset.top]];
+ constant:8.0 + self.contentInset.top]];
[self.compassViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:self
@@ -775,7 +775,7 @@ public:
toItem:self.compassView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
- constant:5.0 + self.contentInset.right]];
+ constant:8.0 + self.contentInset.right]];
[containerView addConstraints:self.compassViewConstraints];
@@ -792,7 +792,7 @@ public:
toItem:viewController.topLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1.0
- constant:5.0]];
+ constant:8.0]];
}
[self.scaleBarConstraints addObject:
[NSLayoutConstraint constraintWithItem:self.scaleBar
@@ -801,7 +801,7 @@ public:
toItem:self
attribute:NSLayoutAttributeTop
multiplier:1.0
- constant:5.0 + self.contentInset.top]];
+ constant:8.0 + self.contentInset.top]];
[self.scaleBarConstraints addObject:
[NSLayoutConstraint constraintWithItem:self.scaleBar
attribute:NSLayoutAttributeLeft
@@ -835,7 +835,7 @@ public:
toItem:self.logoView
attribute:NSLayoutAttributeBaseline
multiplier:1
- constant:8 + self.contentInset.bottom]];
+ constant:8.0 + self.contentInset.bottom]];
[self.logoViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:self.logoView
attribute:NSLayoutAttributeLeading
@@ -859,7 +859,7 @@ public:
toItem:self.attributionButton
attribute:NSLayoutAttributeBaseline
multiplier:1
- constant:8 + self.contentInset.bottom]];
+ constant:8.0 + self.contentInset.bottom]];
}
[self.attributionButtonConstraints addObject:
[NSLayoutConstraint constraintWithItem:self
@@ -868,7 +868,7 @@ public:
toItem:self.attributionButton
attribute:NSLayoutAttributeBaseline
multiplier:1
- constant:8 + self.contentInset.bottom]];
+ constant:8.0 + self.contentInset.bottom]];
[self.attributionButtonConstraints addObject:
[NSLayoutConstraint constraintWithItem:self
@@ -877,29 +877,20 @@ public:
toItem:self.attributionButton
attribute:NSLayoutAttributeTrailing
multiplier:1
- constant:8 + self.contentInset.right]];
+ constant:8.0 + self.contentInset.right]];
[containerView addConstraints:self.attributionButtonConstraints];
}
- (void)updateConstraints
{
-
-// If compiling with the iOS 11+ SDK
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
// If safeAreaLayoutGuide API exists
- if ( [self respondsToSelector:@selector(safeAreaLayoutGuide)] ) {
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+ if (@available(iOS 11.0, *)) {
UILayoutGuide *safeAreaLayoutGuide = self.safeAreaLayoutGuide;
-#pragma clang diagnostic pop
+
// compass view
[self removeConstraints:self.compassViewConstraints];
[self.compassViewConstraints removeAllObjects];
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
- [self.compassViewConstraints addObject:[self.compassView.topAnchor constraintEqualToSystemSpacingBelowAnchor:safeAreaLayoutGuide.topAnchor multiplier:1]];
-#pragma clang diagnostic pop
+ [self.compassViewConstraints addObject:[self constraintForYAxisAnchor:self.compassView.topAnchor belowAnchor:safeAreaLayoutGuide.topAnchor]];
[self.compassViewConstraints addObject:[safeAreaLayoutGuide.rightAnchor constraintEqualToAnchor:self.compassView.rightAnchor
constant:8.0 + self.contentInset.right]];
[self addConstraints:self.compassViewConstraints];
@@ -907,10 +898,7 @@ public:
// scale bar view
[self removeConstraints:self.scaleBarConstraints];
[self.scaleBarConstraints removeAllObjects];
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
- [self.scaleBarConstraints addObject:[self.scaleBar.topAnchor constraintEqualToSystemSpacingBelowAnchor:safeAreaLayoutGuide.topAnchor multiplier:1]];
-#pragma clang diagnostic pop
+ [self.scaleBarConstraints addObject:[self constraintForYAxisAnchor:self.scaleBar.topAnchor belowAnchor:safeAreaLayoutGuide.topAnchor]];
[self.scaleBarConstraints addObject:[self.scaleBar.leftAnchor constraintEqualToAnchor:safeAreaLayoutGuide.leftAnchor
constant:8.0 + self.contentInset.left]];
[self addConstraints:self.scaleBarConstraints];
@@ -918,8 +906,7 @@ public:
// logo view
[self removeConstraints:self.logoViewConstraints];
[self.logoViewConstraints removeAllObjects];
- [self.logoViewConstraints addObject:[safeAreaLayoutGuide.bottomAnchor constraintEqualToAnchor:self.logoView.bottomAnchor
- constant:8.0 + self.contentInset.bottom]];
+ [self.logoViewConstraints addObject:[self constraintForYAxisAnchor:safeAreaLayoutGuide.bottomAnchor belowAnchor:self.logoView.bottomAnchor]];
[self.logoViewConstraints addObject:[self.logoView.leftAnchor constraintEqualToAnchor:safeAreaLayoutGuide.leftAnchor
constant:8.0 + self.contentInset.left]];
[self addConstraints:self.logoViewConstraints];
@@ -927,21 +914,26 @@ public:
// attribution button
[self removeConstraints:self.attributionButtonConstraints];
[self.attributionButtonConstraints removeAllObjects];
- [self.attributionButtonConstraints addObject:[safeAreaLayoutGuide.bottomAnchor constraintEqualToAnchor:self.attributionButton.bottomAnchor
- constant:8.0 + self.contentInset.bottom]];
+ [self.attributionButtonConstraints addObject:[self constraintForYAxisAnchor:safeAreaLayoutGuide.bottomAnchor belowAnchor:self.attributionButton.bottomAnchor]];
[self.attributionButtonConstraints addObject:[safeAreaLayoutGuide.rightAnchor constraintEqualToAnchor:self.attributionButton.rightAnchor
constant:8.0 + self.contentInset.right]];
[self addConstraints:self.attributionButtonConstraints];
} else {
[self updateConstraintsPreiOS11];
}
-#else
- [self updateConstraintsPreiOS11];
-#endif
[super updateConstraints];
}
+- (NSLayoutConstraint *)constraintForYAxisAnchor:(NSLayoutYAxisAnchor *)yAxisAnchor belowAnchor:(NSLayoutYAxisAnchor *)anchor
+{
+ if (@available(iOS 11.0, *)) {
+ return [yAxisAnchor constraintEqualToSystemSpacingBelowAnchor:anchor multiplier:1];
+ } else {
+ return nil;
+ }
+}
+
- (BOOL)isOpaque
{
return _opaque;
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 4f1413d300..d59972f5bf 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -54,6 +54,9 @@ static NSString *const MGLEventKeySessionId = @"sessionId";
static NSString *const MGLEventKeyApplicationState = @"applicationState";
static NSString *const MGLEventKeyAltitude = @"altitude";
+static NSString *const MGLMapboxAccountType = @"MGLMapboxAccountType";
+static NSString *const MGLMapboxMetricsEnabled = @"MGLMapboxMetricsEnabled";
+
// SDK event source
static NSString *const MGLEventSource = @"mapbox";
@@ -124,6 +127,8 @@ const NSTimeInterval MGLFlushInterval = 180;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSDate *instanceIDRotationDate;
@property (nonatomic) NSDate *nextTurnstileSendDate;
+@property (nonatomic) NSNumber *currentAccountTypeValue;
+@property (nonatomic) BOOL currentMetricsEnabledValue;
@end
@@ -135,10 +140,10 @@ const NSTimeInterval MGLFlushInterval = 180;
+ (void)initialize {
if (self == [MGLMapboxEvents class]) {
NSBundle *bundle = [NSBundle mainBundle];
- NSNumber *accountTypeNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccountType"];
+ NSNumber *accountTypeNumber = [bundle objectForInfoDictionaryKey:MGLMapboxAccountType];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
- @"MGLMapboxAccountType": accountTypeNumber ?: @0,
- @"MGLMapboxMetricsEnabled": @YES,
+ MGLMapboxAccountType: accountTypeNumber ?: @0,
+ MGLMapboxMetricsEnabled: @YES,
@"MGLMapboxMetricsDebugLoggingEnabled": @NO,
}];
}
@@ -152,8 +157,8 @@ const NSTimeInterval MGLFlushInterval = 180;
if ([NSProcessInfo instancesRespondToSelector:@selector(isLowPowerModeEnabled)]) {
isLowPowerModeEnabled = [[NSProcessInfo processInfo] isLowPowerModeEnabled];
}
- return ([[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"] &&
- [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0 &&
+ return ([[NSUserDefaults standardUserDefaults] boolForKey:MGLMapboxMetricsEnabled] &&
+ [[NSUserDefaults standardUserDefaults] integerForKey:MGLMapboxAccountType] == 0 &&
!isLowPowerModeEnabled);
#endif
}
@@ -167,6 +172,9 @@ const NSTimeInterval MGLFlushInterval = 180;
- (instancetype) init {
self = [super init];
if (self) {
+ _currentAccountTypeValue = @0;
+ _currentMetricsEnabledValue = YES;
+
_appBundleId = [[NSBundle mainBundle] bundleIdentifier];
_apiClient = [[MGLAPIClient alloc] init];
@@ -249,38 +257,61 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)userDefaultsDidChange:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self pauseOrResumeMetricsCollectionIfRequired];
- });
+
+ // Guard against over calling pause / resume if the values this implementation actually
+ // cares about have not changed
+
+ if ([[notification object] respondsToSelector:@selector(objectForKey:)]) {
+ NSUserDefaults *userDefaults = [notification object];
+
+ NSNumber *accountType = [userDefaults objectForKey:MGLMapboxAccountType];
+ BOOL metricsEnabled = [[userDefaults objectForKey:MGLMapboxMetricsEnabled] boolValue];
+
+ if (![accountType isEqualToNumber:self.currentAccountTypeValue] || metricsEnabled != self.currentMetricsEnabledValue) {
+ [self pauseOrResumeMetricsCollectionIfRequired];
+ self.currentAccountTypeValue = accountType;
+ self.currentMetricsEnabledValue = metricsEnabled;
+ }
+ }
+
}
- (void)pauseOrResumeMetricsCollectionIfRequired {
- UIApplication *application = [UIApplication sharedApplication];
-
- // Prevent blue status bar when host app has `when in use` permission only and it is not in foreground
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse &&
- application.applicationState == UIApplicationStateBackground) {
-
- if (_backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
- _backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
- [application endBackgroundTask:_backgroundTaskIdentifier];
- _backgroundTaskIdentifier = UIBackgroundTaskInvalid;
- }];
- [self flush];
- }
-
- [self pauseMetricsCollection];
- return;
- }
-
- // Toggle pause based on current pause state, user opt-out state, and low-power state.
- BOOL enabled = [[self class] isEnabled];
- if (self.paused && enabled) {
- [self resumeMetricsCollection];
- } else if (!self.paused && !enabled) {
- [self flush];
- [self pauseMetricsCollection];
- }
+
+ // [CLLocationManager authorizationStatus] has been found to block in some cases so
+ // dispatch the call to a non-UI thread
+ dispatch_async(self.serialQueue, ^{
+ CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
+
+ // Checking application state must be done on the main thread for safety and
+ // to avoid a thread sanitizer error
+ dispatch_async(dispatch_get_main_queue(), ^{
+ UIApplication *application = [UIApplication sharedApplication];
+ UIApplicationState state = application.applicationState;
+
+ // Prevent blue status bar when host app has `when in use` permission only and it is not in foreground
+ if (status == kCLAuthorizationStatusAuthorizedWhenInUse && state == UIApplicationStateBackground) {
+ if (_backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
+ _backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
+ [application endBackgroundTask:_backgroundTaskIdentifier];
+ _backgroundTaskIdentifier = UIBackgroundTaskInvalid;
+ }];
+ [self flush];
+ }
+ [self pauseMetricsCollection];
+ return;
+ }
+
+ // Toggle pause based on current pause state, user opt-out state, and low-power state.
+ BOOL enabled = [[self class] isEnabled];
+ if (self.paused && enabled) {
+ [self resumeMetricsCollection];
+ } else if (!self.paused && !enabled) {
+ [self flush];
+ [self pauseMetricsCollection];
+ }
+ });
+ });
}
- (void)pauseMetricsCollection {
@@ -602,7 +633,7 @@ const NSTimeInterval MGLFlushInterval = 180;
BOOL metricsEnabledSettingShownInAppFlag = [shownInAppNumber boolValue];
if (!metricsEnabledSettingShownInAppFlag &&
- [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0) {
+ [[NSUserDefaults standardUserDefaults] integerForKey:MGLMapboxAccountType] == 0) {
// Opt-out is not configured in UI, so check for Settings.bundle
id defaultEnabledValue;
NSString *appSettingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
@@ -612,7 +643,7 @@ const NSTimeInterval MGLFlushInterval = 180;
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[appSettingsBundle stringByAppendingPathComponent:@"Root.plist"]];
NSArray *preferences = settings[@"PreferenceSpecifiers"];
for (NSDictionary *prefSpecification in preferences) {
- if ([prefSpecification[@"Key"] isEqualToString:@"MGLMapboxMetricsEnabled"]) {
+ if ([prefSpecification[@"Key"] isEqualToString:MGLMapboxMetricsEnabled]) {
defaultEnabledValue = prefSpecification[@"DefaultValue"];
}
}
diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m
new file mode 100644
index 0000000000..a41e7695f9
--- /dev/null
+++ b/platform/ios/test/MGLMapViewLayoutTests.m
@@ -0,0 +1,108 @@
+#import <XCTest/XCTest.h>
+#import "MGLMapView.h"
+#import "MGLMapViewDelegate.h"
+#import "MGLAccountManager.h"
+
+
+@interface MGLMapViewLayoutTests : XCTestCase<MGLMapViewDelegate>
+
+@property (nonatomic) UIView *superView;
+@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) XCTestExpectation *styleLoadingExpectation;
+
+@end
+
+@implementation MGLMapViewLayoutTests
+
+- (void)setUp {
+ [super setUp];
+
+ [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
+ NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
+
+ self.superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds];
+
+ self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL];
+ self.mapView.delegate = self;
+
+ [self.superView addSubview:self.mapView];
+
+ UIView *mapView = self.mapView;
+ NSDictionary *bindings = NSDictionaryOfVariableBindings(mapView);
+ NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings];
+ NSArray *horizonatalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings];
+
+ [self.superView addConstraints:[verticalConstraints arrayByAddingObjectsFromArray:horizonatalConstraints]];
+
+ self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."];
+ [self waitForExpectationsWithTimeout:1 handler:nil];
+
+ //set zoom and heading so that scale bar and compass will be shown
+ [self.mapView setZoomLevel:4.5 animated:NO];
+ [self.mapView.camera setHeading:12.0];
+
+ //invoke layout
+ [self.superView setNeedsLayout];
+ [self.superView layoutIfNeeded];
+
+}
+
+- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
+ XCTAssertNotNil(mapView.style);
+ XCTAssertEqual(mapView.style, style);
+
+ [self.styleLoadingExpectation fulfill];
+}
+
+- (void)tearDown {
+ self.styleLoadingExpectation = nil;
+ self.mapView = nil;
+
+ [super tearDown];
+}
+
+- (void)testOrnamentPlacement {
+
+ CGFloat margin = 8.0;
+ CGFloat bottomSafeAreaInset = 0.0;
+ double accuracy = 0.01;
+
+ if ( [self.mapView respondsToSelector:@selector(safeAreaInsets)] ) {
+ bottomSafeAreaInset = self.mapView.safeAreaInsets.bottom;
+ }
+
+ //compass
+ UIImageView *compassView = self.mapView.compassView;
+
+ CGFloat expectedCompassOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(compassView.frame);
+ CGFloat expectedCompassOriginY = margin;
+
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(compassView.frame), expectedCompassOriginX, accuracy);
+ XCTAssertEqualWithAccuracy(CGRectGetMinY(compassView.frame), expectedCompassOriginY, accuracy);
+
+ //scale bar
+ UIView *scaleBar = self.mapView.scaleBar;
+
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), margin, accuracy);
+ XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), margin, accuracy);
+
+ //attribution button
+ UIButton *attributionButton = self.mapView.attributionButton;
+
+ CGFloat expectedButtonOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(attributionButton.frame);
+ CGFloat expectedButtonOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(attributionButton.frame);
+
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(attributionButton.frame), expectedButtonOriginX, accuracy);
+ XCTAssertEqualWithAccuracy(CGRectGetMinY(attributionButton.frame), expectedButtonOriginY, accuracy);
+
+ //mapbox logo
+ UIImageView *logoView = self.mapView.logoView;
+
+ CGFloat expectedLogoOriginX = margin;
+ CGFloat expectedLogoOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(logoView.frame);
+
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(logoView.frame), expectedLogoOriginX, accuracy);
+ XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), expectedLogoOriginY, accuracy);
+}
+
+@end