mapbox-directions-swift icon indicating copy to clipboard operation
mapbox-directions-swift copied to clipboard

Directions crash when accessToken is not provided - it should use token from MGLMapboxAccessToken

Open wojciech-kulik opened this issue 5 years ago • 2 comments

Steps to reproduce

  1. Set token using MGLAccountManager.accessToken = "123123"
  2. 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.

wojciech-kulik avatar Dec 21 '19 10:12 wojciech-kulik

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.

wojciech-kulik avatar Dec 22 '19 15:12 wojciech-kulik

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.

1ec5 avatar Dec 26 '19 21:12 1ec5