mapbox / mapbox/mapbox-maps-ios
Attribution crashes because parentViewController is nil
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 14
- iOS version: latest
- Devices affected: all
- Maps SDK Version: 10.10.1
## Observed behavior and steps to reproduce
The attribution buttons tries to open the dialog on the `parentViewController` here: https://github.com/mapbox/mapbox-maps-ios/blob/192437b31f46860d10900e227dfc36ef30aaa130/Sources/MapboxMaps/Foundation/MapView%2BAttribution.swift#L6
However, this can be `nil` (SwiftUI, Ionic/cordova etc.) and leads to a crash.
## Expected behavior
To not crash 😇
## Additional links and references
A quick workaround for me is:
```swift
func viewControllerForPresenting(_ attributionDialogManager: AttributionDialogManager) -> UIViewController {
return (UIApplication.shared.delegate?.window??.rootViewController!)!
}
```
This could serve as a fallback in case the `parentViewController` is actually `nil`.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Sources/MapboxMaps/Foundation/MapView+Attribution.swift at the attribution dialog presentation code linked in the issue. Trace how the presenting view controller is selected and verify the attribution action no longer crashes when parentViewController is nil; the issue's expected outcome is a safe behavior in that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100