In my iOS app in order to switch between normal and satellite view on a map and because SwiftUI's Map does not support map type on iOS 16 (support is required), I am wrapping MKMapView in a UIViewRepresentable and integrate it in a normal SwiftUI View.
import Foundation
import MapKit
import SwiftUI
struct MapView: UIViewRepresentable {
@Binding var region: MKCoordinateRegion
@Binding var showSatelliteView: Bool
@Binding var followUser: Bool
func makeUIView(context: Context) -> MKMapView {
let mkMapView = MKMapView(frame: .zero)
mkMapView.delegate = context.coordinator
updateMKMapView(mkMapView)
return mkMapView
}
func updateUIView(_ mkMapView: MKMapView, context: Context) {
updateMKMapView(mkMapView)
}
fileprivate func updateMKMapView(_ mkMapView: MKMapView) {
mkMapView.setRegion(region, animated: true)
mkMapView.preferredConfiguration = showSatelliteView ? MKImageryMapConfiguration() : MKStandardMapConfiguration()
mkMapView.userTrackingMode = followUser ? .follow : .none
}
// MARK: Coordinator
final class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView
init(_ parent: MapView) {
self.parent = parent
}
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
parent.region = mapView.region
}
func mapView(
_ mapView: MKMapView,
didChange mode: MKUserTrackingMode,
animated: Bool
) {
parent.followUser = mapView.userTrackingMode == .follow || mapView.userTrackingMode == .followWithHeading
}
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
}
showSatelliteView is initially set to false. I then change it to true and then back to false from a bound toggle button in the hosting View. As this last change happens on those devices
- physical iPad Pro 9.7" iOS 16.7.4
- simulator iPad mini 6th gen iOS 16.4
I get following error
[RegistryManager] Tracking a LayerData with no associated Registry: Assertion with expression - layerDataSets.keys.exiting.empty() : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/RegistryManager.mm line - 473
Followed by repeated
[MeshRenderableLogic] Tracking renderables for inactive registry
[MeshRenderableLogic] Tracking renderables for inactive registry
... (140+)
until it crashes with signal SIGABRT
The same errors are produced on simulator iPhone 15 Pro iOS 17.0.1 and simulator iPad mini 6th gen iOS 17.2 but without crashing.
Do you have a clue about what is causing the crash?
Got the same error message (XCode15/macOS) when switching between standard and hybrid mode for the second time (standard -> hybrid -> standard, error). Crash after a few times switching. I use overlays to show a track on the map. After removing the overlays when switching and reading them the app no more crashed. Error messages stayed. Perhaps this gives you a directions to search in.