mapbox / mapbox/mapbox-directions-swift

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

Open
#396 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backwards incompatible improvement
Dominant language
Swift
Stars
206
Forks
99
Avg merge
7h 54m
Merged PRs (30d)
3

Description

### 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 . 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`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue points to Directions.init(accessToken:host:) and its defaultAccessToken fallback; start there and inspect how MGLAccountManager.accessToken is exposed. Reproduce with MGLAccountManager.accessToken set and Directions() without a parameter, then verify initialization succeeds using that token.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.