Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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. #122

Open
trunghvbk opened this issue Jul 6, 2023 · 0 comments

Comments

@trunghvbk
Copy link

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
Screenshot 2023-07-06 at 16 39 58

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
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant