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

Remove redundant didChangeAuthorizationStatus: in favor of didFailWithError: #1608

Closed
wants to merge 1 commit into from
Closed

Remove redundant didChangeAuthorizationStatus: in favor of didFailWithError: #1608

wants to merge 1 commit into from

Conversation

friedbunny
Copy link
Contributor

This PR removes locationManager:didChangeAuthorizationStatus: in favor of locationManager:didFailWithError: for turning off the map's location features and for notifying the developer of location permission changes.

Setting showsUserLocation = NO in locationManager:didChangeAuthorizationStatus: would turn off the location manager, which meant that the subsequent call to locationManager:didFailWithError: would never happen, nor would the call to our mapView:didFailToLocateUserWithError: delegate method.

Supercedes #1598.

/cc @incanus @1ec5 @bleege

…hError:

Listening to both `locationManager:didChangeAuthorizationStatus:` and `locationManager:didFailWithError:` delegate methods is unnecessary. Setting `showsUserLocation = NO` in the first means that the second never gets called and our `mapView:didFailToLocateUserWithError:` delegate method never gets called.
@friedbunny
Copy link
Contributor Author

I tested this with access to location services denied (kCLAuthorizationStatusDenied) and device-level "restricted" (kCLAuthorizationStatusRestricted).

Both worked with locationManager:didFailWithError:, though gave the same kCLErrorDenied error.

This is also how MapKit behaves.

@jfirebaugh
Copy link
Contributor

Committed as f5c1e26.

@jfirebaugh jfirebaugh closed this Jun 25, 2015
@friedbunny friedbunny added this to the iOS Beta 3 milestone Jun 25, 2015
@friedbunny friedbunny deleted the actually-i-sort-of-like-didFailWithError branch June 25, 2015 23:38
@MadeByDouglas
Copy link

As a user of mapBox following this discussion, I'm curious what your best practice recommendation are for handling various user authorization scenarios. For example, I have mapView.showsUserLocation = true in viewDidLoad, this seems to work as expected if the user accepts or denies the iOS message.

However, on subsequent openings of the map, if the status is denied I would like to send a message suggesting the user to change their settings in iOS, what is the best way to do this with just using MapBox and not needing to import CoreLocation and calling didChangeAuthorizationStatus ?

It seems from this discussion it would be didFailToLocateUserWithError however how do I properly parse that NSError? I just get NSError domain: "kCLErrorDomain" - code: 1 What do I do with that? How do I know thats an error because authorization and not something else. It seems it would be more intuitive if it still passed the CLAuthorizationStatus object.

@friedbunny
Copy link
Contributor Author

NSError domain: "kCLErrorDomain" - code: 1 is kCLErrorDenied. You can see the rest of the kCLErrorDomain enum definitions in Apple’s docs.

You should compare the incoming error object against kCLErrorDenied/CLError.Denied:

func mapView(mapView: MGLMapView, didFailToLocateUserWithError error: NSError) {
    if error.domain == kCLErrorDomain && error.code == CLError.Denied.rawValue {
        ...
    }
}

@MadeByDouglas
Copy link

ahh, ok that makes sense, thank you, i appreciate the apple docs link too

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants