mapbox / mapbox/mapbox-maps-ios

Attribution crashes because parentViewController is nil

Open
#1,911 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.