mapbox-navigation-ios icon indicating copy to clipboard operation
mapbox-navigation-ios copied to clipboard

[Bug]: Crash on re-routing due to Access Token not set in Directions.Shared (Dynamic Access Token)

Open emilianoalvarez91 opened this issue 1 year ago • 4 comments

Mapbox Navigation SDK version

v3.1.1

Steps to reproduce

  1. Don't set the access token in info.plist;
  2. Set the access token dynamically by configuring: MapboxNavigationProvider(coreConfig: .init(credentials: .init(accesstoken: "{{Access_token}}")))
  3. Calculate routes: navigationProvider.mapboxNavigation.routingProvider().calculateRoutes(options: routeOptions).value
  4. Start Active Navigation;
  5. Do not follow the path and wait for a rerouting to happen.

Expected behavior

Rerouting happens and new route is generated.

Actual behavior

App crashes due to Swift runtime failure: precondition failure caused by MapboxDirections.Directions.shared.credentials not being set

I've tried setting MapboxOptions.accessToken = "{{Access_token}}" and it also doesn't work, but works correctly on Android Nav SDK. This issue is causing a problem because we don't want to expose the api token in the info.plist but have rotating tokens.

Is this a one-time issue or a repeatable issue?

repeatable

emilianoalvarez91 avatar Jul 01 '24 11:07 emilianoalvarez91

Hello @emilianoalvarez91. Thank you for your request. I just want to clarify, how do you start Active Navigation? Do you apply any new configuration to config before Active Navigation start?

chizhavko avatar Jul 01 '24 17:07 chizhavko

Hi @chizhavko, sure! I don't apply any new configuration before active navigation.

How I instantiate the MapboxNavigationProvider:

private let navigationProvider: MapboxNavigationProvider

init() {
  let config = CoreConfig(
    credentials: .init(accessToken: "{{Access_token}}")
  )
  self.navigationProvider = MapboxNavigationProvider(coreConfig: config)
}

Once I get the routes I do:

private func startNavigation() { 
  navigationProvider.mapboxNavigation.tripSession().startActiveGuidance(with: navigationRoutes, startLegIndex: 0)
  cameraState = .following
}

I thought in the beginning that it could be an issue with custom navigation as I wasn't using the NavigationViewController, so then I rebuild everything using the navigationController and start the navigation by doing:

 let navigationOptions = NavigationOptions(
    mapboxNavigation: navigationProvider.mapboxNavigation,
    voiceController: navigationProvider.routeVoiceController,
    eventsManager: navigationProvider.eventsManager(),
    styles: [DayStyle()],
    predictiveCacheManager: navigationProvider.predictiveCacheManager,
    navigationMapView: navigationMapView
)

let navigationViewController = NavigationViewController(
    navigationRoutes: navigationRoutes,
    navigationOptions: navigationOptions
)

In both cases, the same issue occurs. Active navigation starts correctly, but once a rerouting occurs the SDK crashes. It seems that behind the scenes the SDK uses the Directions.shared singleton which is instantiated automatically by reading the value from MBXAccessToken in the info.plist. If the key is not there, it will lead to a crash, which is unexpected as I'm setting the access token through MapboxNavigationProvider coreConfig's credentials and I would expect that the SDK sets this token everywhere.

I tried finding a way to set the access token to the Directions' singleton, but there isn't a way.

emilianoalvarez91 avatar Jul 01 '24 20:07 emilianoalvarez91

Hello @emilianoalvarez91 After some investigation i still cannot reproduce the issue, do you have sample project or do you know which precondition cause the failure? There is no MapboxDirections.Directions.shared.credentials not being set in our codebase.

chizhavko avatar Jul 02 '24 16:07 chizhavko

It can be reproduced with the CoreSDKExample

Steps to reproduce:

  1. Remove from the Info.plist the MBXAccessToken;
  2. Provide a valid access token in the Navigation.swift file in line 24;
  3. Run the app in the simulator or physical device;
  4. Long press to generate a route and start navigation;
  5. Go to Features/Location/Custom Location from the Simulator's top menu bar and choose any location to cause a re routing.

App crashes

Herewith is a video, showcasing it: https://github.com/mapbox/mapbox-navigation-ios/assets/17701694/53dbdfb6-d899-4bb7-9a6c-545f87c090b2

emilianoalvarez91 avatar Jul 02 '24 20:07 emilianoalvarez91

@emilianoalvarez91 Thank you for your ticket. After investigation we found that this issue already resolved on our side and we planing to release fix in next release.

chizhavko avatar Jul 10 '24 17:07 chizhavko

Hello @emilianoalvarez91 We recently released new 3.2.0 version of our SDK. Can you take a look please?

chizhavko avatar Jul 15 '24 13:07 chizhavko

I cannot test the new version 3.2.0 in a physical device as I'm not using SPM in the project. When I'm trying to fetch version 3.2.0 I've noticed that you are not exposing MapboxDirections, MapboxNavigationCore, MapboxNavigationUIKit and _MapboxNavigationHelpers as binaries, so I'm not able to upgrade and test.

emilianoalvarez91 avatar Jul 28 '24 22:07 emilianoalvarez91

The issue about the SDK distribution is discussed in #4703

kried avatar Aug 01 '24 11:08 kried