Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Refactor iOS location authorization delegate method #1598

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@ IB_DESIGNABLE
* @param error An error object containing the reason why location tracking failed. */
- (void)mapView:(MGLMapView *)mapView didFailToLocateUserWithError:(NSError *)error;

/** Tells the delegate that location authorization status has changed.
*
* When the user allows or denies use of their location, this method is called with the appropriate status. When explicitly denied, status will be set to kCLAuthorizationStatusDenied.
*
* See [Apple's CoreLocation Framework Reference](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/c/tdef/CLAuthorizationStatus) for other possible statuses.
*
* @param mapView The map view that is tracking the user’s location.
* @param status A CLAuthorizationStatus constant indicating whether the app is authorized to use location services. */
- (void)mapView:(MGLMapView *)mapView didChangeLocationAuthorizationStatus:(CLAuthorizationStatus)status;

/** Tells the delegate that the map view’s user tracking mode has changed.
*
* This method is called after the map view asynchronously changes to reflect the new user tracking mode, for example by beginning to zoom or rotate.
Expand Down
14 changes: 10 additions & 4 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2120,19 +2120,25 @@ - (void)locationManager:(__unused CLLocationManager *)manager didChangeAuthoriza
self.userTrackingMode = MGLUserTrackingModeNone;
self.showsUserLocation = NO;
}

if ([self.delegate respondsToSelector:@selector(mapView:didChangeLocationAuthorizationStatus:)])
{
[self.delegate mapView:self didChangeLocationAuthorizationStatus:status];
}
}

- (void)locationManager:(__unused CLLocationManager *)manager didFailWithError:(NSError *)error
{
// never called?
if ([error code] == kCLErrorDenied)
{
self.userTrackingMode = MGLUserTrackingModeNone;
self.showsUserLocation = NO;
}

if ([self.delegate respondsToSelector:@selector(mapView:didFailToLocateUserWithError:)])
{
[self.delegate mapView:self didFailToLocateUserWithError:error];
}
if ([self.delegate respondsToSelector:@selector(mapView:didFailToLocateUserWithError:)])
{
[self.delegate mapView:self didFailToLocateUserWithError:error];
}
}

Expand Down