mapbox-directions-swift
mapbox-directions-swift copied to clipboard
Directions crash when accessToken is not provided - it should use token from MGLMapboxAccessToken
Steps to reproduce
- Set token using
MGLAccountManager.accessToken = "123123" - Create object
Directions()
Expected behavior
Directions should be properly initialized with a token set using MGLAccountManager.accessToken if not provided via parameter or info.plist
Actual behavior
There is a crash. Check this internal implementation of init:
public init(accessToken: String?, host: String?) {
let accessToken = accessToken ?? defaultAccessToken
precondition(accessToken != nil && !accessToken!.isEmpty, "A Mapbox access token is required. Go to <https://account.mapbox.com/access-tokens/>. In Info.plist, set the MGLMapboxAccessToken key to your access token, or use the Directions(accessToken:host:) initializer.")
...
}
it uses accessToken from parameter or defaultAccessToken which is the one from info.plist. However, it is not using MGLAccountManager.accessToken.
I was trying to add ?? MGLAccountManager.accessToken in init in Directions.swift but I see that you don't have access to the Mapbox module there.
By design, MapboxDirections.swift doesn’t depend on the map SDK, though the navigation SDK does. If an application is already programmatically setting MGLAccountManager.accessToken, it can pass MGLAccountManager.accessToken (or the access token as a string literal) into the Directions(accessToken:host:) initializer.