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

Crash updating user location indicator on iOS 14 with custom location manager — -[MGLFaux3DUserLocationAnnotationView update] #470

Closed
1ec5 opened this issue Sep 22, 2020 · 0 comments · Fixed by #474
Labels
bug Something isn't working ios status: triage
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Sep 22, 2020

On iOS 14, a crash occurs as soon as a location update comes in after setting MGLMapView.locationManager to an MGLLocationManager implementation that has not been updated to implement the accuracyAuthorization property and -locationManagerDidChangeAuthorization: method.

Crash details

As of iOS navigation SDK v1.0.0-rc.4, the PassiveLocationManager class added in mapbox/mapbox-navigation-ios#2410 doesn’t implement these methods – mapbox/mapbox-navigation-ios#2554 – leading to the following crash:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x180f5a5ac __exceptionPreprocess
1  libobjc.A.dylib                0x194fd442c objc_exception_throw
2  CoreFoundation                 0x180e64a2c -[NSOrderedSet initWithSet:copyItems:]
3  CoreFoundation                 0x180f5ce6c ___forwarding___
4  CoreFoundation                 0x180f5f420 _CF_forwarding_prep_0
5  Mapbox                         0x101f9a5e4 -[MGLFaux3DUserLocationAnnotationView update] + 62 (MGLFaux3DUserLocationAnnotationView.mm:62)
6  Mapbox                         0x102015208 -[MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:] + 7207 (MGLMapView.mm:7207)
7  Mapbox                         0x10200fd3c -[MGLMapView locationManager:didUpdateLocations:animated:completionHandler:] + 6191 (MGLMapView.mm:6191)
8  Mapbox                         0x10200f968 -[MGLMapView locationManager:didUpdateLocations:] + 6157 (MGLMapView.mm:6157)
9  MapboxNavigation               0x101b30fec specialized PassiveLocationManager.passiveLocationDataSource(_:didUpdateLocation:rawLocation:) + 78 (PassiveLocationManager.swift:78)
10 MapboxCoreNavigation           0x100a614c4 specialized PassiveLocationDataSource.locationManager(_:didUpdateLocations:) + 139 (PassiveLocationDataSource.swift:139)
11 MapboxCoreNavigation           0x100a60514 @objc PassiveLocationDataSource.locationManager(_:didUpdateLocations:) (<compiler-generated>)
12 CoreLocation                   0x186cd0dd0 CLClientStopVehicleHeadingUpdates
13 CoreLocation                   0x186cd0074 CLClientStopVehicleHeadingUpdates
…

Diagnosis

The immediate issue is that this code refers to the accuracyAuthorization property, which is unimplemented by PassiveLocationManager and thus missing from the object’s storage:

if (self.mapView.locationManager.accuracyAuthorization == CLAccuracyAuthorizationFullAccuracy) {

mapbox/mapbox-navigation-ios#2554 tracks updating the PassiveLocationManager implementation to somehow include the new iOS 14 members. Even so, a developer would be forgiven for omitting this implementation, because it’s marked as an optional member in the header:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
/**
Specifies the level of location accuracy the Maps SDK has permission to use.
@note If the value of this property is `CLAccuracyAuthorizationFullAccuracy`, you can set the
`MGLLocationManager.desiredAccuracy` property to any value. If the value is `CLAccuracyAuthorizationReducedAccuracy`,
setting `MGLLocationManager.desiredAccuracy` to a value other than` kCLLocationAccuracyReduced` has no effect on
the location information.
*/
- (CLAccuracyAuthorization)accuracyAuthorization API_AVAILABLE(ios(14));
#endif

In fact, plenty of other code throughout MGLMapView makes use of these ostensibly optional members, potentially setting up a situation for a crash:

if (self.locationManager.headingOrientation != orientation)

Expected behavior

MGLMapView should check that any optional method or property of MGLLocationManager is implemented before using it.

In theory, it would be within the map SDK’s purview to make accuracyAuthorization and -locationManagerDidChangeAuthorization: required. However, that would be oddly inconsistent with the rest of the MGLLocationManager protocol, including more prominent members such as location and heading. Moreover, it would technically be a backwards-incompatible change.

/ref #381 (comment)
/cc @mapbox/maps-ios @mapbox/navigation-ios @mapbox/1tap-ios

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working ios status: triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants