summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-07-11 15:31:29 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2018-07-20 09:46:38 -0700
commit97de7ace90cde20ac5ff2ba5529c5e8fcc457b5b (patch)
tree8a24fd320c99c40aea09ad67e65e6dd9c3c3bee1
parent9332bc2f60b4dd2cc994b9557f03204d0e676509 (diff)
downloadqtlocation-mapboxgl-97de7ace90cde20ac5ff2ba5529c5e8fcc457b5b.tar.gz
[ios] Change the location manager internal implementation to a category.
-rw-r--r--platform/darwin/src/MGLLocationManager.m96
-rw-r--r--platform/darwin/src/MGLLocationManager_Private.h4
-rw-r--r--platform/ios/src/MGLMapView.mm8
3 files changed, 6 insertions, 102 deletions
diff --git a/platform/darwin/src/MGLLocationManager.m b/platform/darwin/src/MGLLocationManager.m
index af645df231..4349de2f36 100644
--- a/platform/darwin/src/MGLLocationManager.m
+++ b/platform/darwin/src/MGLLocationManager.m
@@ -1,104 +1,10 @@
#import "MGLLocationManager_Private.h"
-@interface MGLCLLocationManager()<CLLocationManagerDelegate>
-
-@property (nonatomic) CLLocationManager *locationManager;
-
-@end
-
-@implementation MGLCLLocationManager
-
-@synthesize delegate;
-
-- (instancetype)init
-{
- if (self = [super init]) {
- _locationManager = [[CLLocationManager alloc] init];
- _locationManager.delegate = self;
- }
- return self;
-}
+@implementation CLLocationManager (MGLAdditions)
- (CLAuthorizationStatus)authorizationStatus
{
return [CLLocationManager authorizationStatus];
}
-- (void)setHeadingOrientation:(CLDeviceOrientation)headingOrientation
-{
- self.locationManager.headingOrientation = headingOrientation;
-}
-
-- (CLDeviceOrientation)headingOrientation
-{
- return self.locationManager.headingOrientation;
-}
-
-- (void)requestAlwaysAuthorization
-{
- [self.locationManager requestAlwaysAuthorization];
-}
-
-- (void)requestWhenInUseAuthorization
-{
- [self.locationManager requestWhenInUseAuthorization];
-}
-
-- (void)startUpdatingHeading
-{
- [self.locationManager startUpdatingHeading];
-}
-
-- (void)startUpdatingLocation
-{
- [self.locationManager startUpdatingLocation];
-}
-
-- (void)stopUpdatingHeading
-{
- [self.locationManager stopUpdatingHeading];
-}
-
-- (void)stopUpdatingLocation
-{
- [self.locationManager stopUpdatingLocation];
-}
-
-- (void)dismissHeadingCalibrationDisplay
-{
- [self.locationManager dismissHeadingCalibrationDisplay];
-}
-
-- (void)dealloc
-{
- [self.locationManager stopUpdatingLocation];
- [self.locationManager stopUpdatingHeading];
- self.delegate = nil;
-}
-
-#pragma mark - CLLocationManagerDelegate
-
-- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
-{
- if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateLocations:)]) {
- [self.delegate locationManager:self didUpdateLocations:locations];
- }
-}
-
-- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
-{
- if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateHeading:)]) {
- [self.delegate locationManager:self didUpdateHeading:newHeading];
- }
-}
-
-- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager
-{
- if ([self.delegate respondsToSelector:@selector(locationManagerShouldDisplayHeadingCalibration:)]) {
- return [self.delegate locationManagerShouldDisplayHeadingCalibration:self];
- }
-
- return NO;
-}
-
@end
diff --git a/platform/darwin/src/MGLLocationManager_Private.h b/platform/darwin/src/MGLLocationManager_Private.h
index 3d1570f0ce..da1ab9bfb2 100644
--- a/platform/darwin/src/MGLLocationManager_Private.h
+++ b/platform/darwin/src/MGLLocationManager_Private.h
@@ -1,6 +1,4 @@
#import "MGLLocationManager.h"
-
-@interface MGLCLLocationManager : NSObject<MGLLocationManager>
-
+@interface CLLocationManager (MGLAdditions) <MGLLocationManager>
@end
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index e0b25b9056..925e8dc5ce 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -694,6 +694,9 @@ public:
[self.attributionButtonConstraints removeAllObjects];
self.attributionButtonConstraints = nil;
+
+ self.locationManager.delegate = nil;
+ self.locationManager = nil;
}
- (void)setDelegate:(nullable id<MGLMapViewDelegate>)delegate
@@ -4693,7 +4696,6 @@ public:
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading];
self.locationManager.delegate = nil;
- _showsUserLocation = NO;
}
_locationManager = locationManager;
_locationManager.delegate = self;
@@ -4708,7 +4710,7 @@ public:
{
// If no custom location manager is provided will use the internal implementation.
if (!self.locationManager) {
- self.locationManager = [[MGLCLLocationManager alloc] init];
+ self.locationManager = [[CLLocationManager alloc] init];
}
if (self.locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined)
@@ -4751,8 +4753,6 @@ public:
{
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading];
- self.locationManager.delegate = nil;
- self.locationManager = nil;
}
}