From 48916354207e7d5d2cc1f152919f370dc2a0da73 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Wed, 30 May 2018 17:01:12 -0400 Subject: [PATCH] [ios] MGLMapView update to new location manager API. --- platform/darwin/src/MGLLocationManager.m | 7 +++++++ platform/ios/ios.xcodeproj/project.pbxproj | 5 +++-- platform/ios/src/MGLMapView.h | 4 +++- platform/ios/src/MGLMapView.mm | 17 ++++++++++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/platform/darwin/src/MGLLocationManager.m b/platform/darwin/src/MGLLocationManager.m index 01f8ac32af7..ad2604d84ba 100644 --- a/platform/darwin/src/MGLLocationManager.m +++ b/platform/darwin/src/MGLLocationManager.m @@ -64,6 +64,13 @@ - (void)stopUpdatingLocation [self.locationManager stopUpdatingLocation]; } +- (void)dealloc +{ + [self.locationManager stopUpdatingLocation]; + [self.locationManager stopUpdatingHeading]; + self.delegate = nil; +} + #pragma mark - CLLocationManagerDelegate - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index ce085570547..db67dd18cca 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -2658,6 +2658,7 @@ }; DA1DC9491CB6C1C2006E619F = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = 26847786Y6; LastSwiftMigration = 0820; }; DA25D5B81CCD9EDE00607828 = { @@ -3628,7 +3629,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 26847786Y6; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; @@ -3641,7 +3642,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 26847786Y6; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index fd0ca19b26a..f7e85f835b2 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -2,7 +2,6 @@ #import "MGLMapCamera.h" #import -#import #import "MGLFoundation.h" #import "MGLTypes.h" @@ -22,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLOverlay; @protocol MGLCalloutView; @protocol MGLFeature; +@protocol MGLLocationManager; /** The default deceleration rate for a map view. */ extern MGL_EXPORT const CGFloat MGLMapViewDecelerationRateNormal; @@ -296,6 +296,8 @@ MGL_EXPORT IB_DESIGNABLE #pragma mark Displaying the User’s Location +@property (nonatomic, nullable) id locationManager; + /** A Boolean value indicating whether the map may display the user location. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7786d11a21b..2fa9d4bcbdc 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -73,6 +73,7 @@ #import "MGLAnnotationContainerView_Private.h" #import "MGLAttributionInfo_Private.h" #import "MGLMapAccessibilityElement.h" +#import "MGLLocationManager_Private.h" #include #include @@ -184,7 +185,7 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) { @interface MGLMapView () )locationManager +{ + _locationManager = locationManager; + _locationManager.delegate = self; + [self validateLocationServices]; +} + - (void)validateLocationServices { BOOL shouldEnableLocationServices = self.showsUserLocation && !self.dormant; if (shouldEnableLocationServices && ! self.locationManager) { - self.locationManager = [[CLLocationManager alloc] init]; + self.locationManager = [[MGLCLLocationManager alloc] init]; if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { @@ -4959,12 +4966,12 @@ - (void)validateUserHeadingUpdating } } -- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations +- (void)locationManager:(MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations { [self locationManager:manager didUpdateLocations:locations animated:YES]; } -- (void)locationManager:(__unused CLLocationManager *)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated +- (void)locationManager:(__unused MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated { CLLocation *oldLocation = self.userLocation.location; CLLocation *newLocation = locations.lastObject;