mapbox / mapbox/MapboxStatic.swift
[CFNetwork] Synchronous URL loading of https://api.mapbox.com/styles/v1/mapbox..... should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 192
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
Xcode show the warning when I tried to access to Snapshot#image:
[CFNetwork] Synchronous URL loading of https://api.mapbox.com/styles/v1/mapbox..... should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.
The class emitted this warning is Snapshot
Please help to check.
This is my sample code:
func takeSnapshot(mapView: MapView, passedLocations: [[CLLocation]]) -> UIImage? {
var overlays = [Overlay]()
overlays.append(contentsOf: markers.compactMap { marker in
if let url = URL(string: marker.type.iconURL) {
return CustomMarker(coordinate: marker.location.coordinate, url: url)
}
return nil
})
passedLocations.forEach { locations in
let coordinates = locations.map { $0.coordinate }
if coordinates.count >= 2 {
let path = Path(
coordinates: coordinates
)
path.strokeColor = UIColor(red: 0.376, green: 0.439, blue: 0.941, alpha: 1)
path.strokeWidth = 3
path.fillColor = .clear
overlays.append(path)
}
}
let center = mapView.cameraState.center
let zoom = mapView.cameraState.zoom
let snapshotCamera = SnapshotCamera(lookingAtCenter: center, zoomLevel: zoom > 20 ? 20 : zoom)
if let styleURL = URL(string: StyleURI.streets.rawValue) {
let options = SnapshotOptions(
styleURL: styleURL,
camera: snapshotCamera,
size: mapView.bounds.size)
options.overlays = overlays
let snapshot = Snapshot(
options: options,
accessToken: MapBoxResource.accessToken
)
return snapshot.image
}
return 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 by reviewing the Snapshot class and the Snapshot#image access shown in the sample. Reproduce the warning with the provided takeSnapshot flow, then trace the image-loading path. Done means the snapshot can be obtained without synchronous URL loading on the main thread and the reported image behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100