Hi,
I have been working with an implementation of MapKit which show custom annotations with a detailCalloutAccessoryView built using SwiftUI. This has been working fine for many years, but starting with macOS Tahoe, somehow the SwiftUI buttons in this view have stopped being tappable.
I have reproduced the issue in the code below ... same code works fine in macOS14 and macOS15 now doesn't work correctly in macOS26:
import Cocoa
import MapKit
import SwiftUI
class ViewController: NSViewController {
private var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
setupMapView()
}
private func setupMapView() {
// Create and configure the map view
mapView = MKMapView()
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.delegate = self
view.addSubview(mapView)
// Pin the map to all edges of the view
NSLayoutConstraint.activate([
mapView.topAnchor.constraint(equalTo: view.topAnchor),
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
// Create an annotation for San Francisco
let sanFranciscoCoordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
let annotation = MKPointAnnotation()
annotation.coordinate = sanFranciscoCoordinate
annotation.title = "San Francisco"
annotation.subtitle = "The City by the Bay"
// Add the annotation to the map
mapView.addAnnotation(annotation)
// Center the map on San Francisco
let region = MKCoordinateRegion(center: sanFranciscoCoordinate,
latitudinalMeters: 5000,
longitudinalMeters: 5000)
mapView.setRegion(region, animated: false)
}
}
// MARK: - MKMapViewDelegate
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "CustomAnnotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
// Create the SwiftUI view for the callout
let calloutView = CalloutContentView()
let hostingView = NSHostingView(rootView: calloutView)
hostingView.frame = NSRect(x: 0, y: 0, width: 200, height: 100)
// Set the SwiftUI view as the detail callout accessory
annotationView?.detailCalloutAccessoryView = hostingView
} else {
annotationView?.annotation = annotation
}
return annotationView
}
}
// MARK: - SwiftUI Callout View
struct CalloutContentView: View {
var body: some View {
VStack(spacing: 12) {
Text("Welcome to San Francisco!")
.font(.headline)
.multilineTextAlignment(.center)
HStack(spacing: 12) {
Button(action: {
print("Directions button tapped")
}) {
Label("Directions", systemImage: "arrow.triangle.turn.up.right.circle.fill")
.font(.caption)
}
.buttonStyle(.borderedProminent)
Button(action: {
print("Info button tapped")
}) {
Label("Info", systemImage: "info.circle.fill")
.font(.caption)
}
.buttonStyle(.bordered)
}
}
.padding()
.frame(width: 200)
}
}
I've looked at other problems with Map and onTap handlers not getting called, but this is a SwiftUI view inside an AppKit MapKit annotation's callout view.
Any idea of how to handle this?