diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-01-17 09:41:37 -0500 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-01-17 09:41:37 -0500 |
commit | 42bcb4b405a4bdc344c6c3d260cf4521e05943cc (patch) | |
tree | ebb421afca52b149677e34fa94b9a08292ede184 /platform/ios/src | |
parent | 69ac7b6922c8b92fbc9beafae3a222703d4fe826 (diff) | |
parent | 2411fb31b70fde6a076886390abdaedde86ea2e5 (diff) | |
download | qtlocation-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/src')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 56 | ||||
-rw-r--r-- | platform/ios/src/MGLMapboxEvents.m | 103 |
2 files changed, 91 insertions, 68 deletions
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"]; } } |