MapView.init reads CLLocationManager.accuracyAuthorization on the main thread, which can hang for seconds
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 69/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- ios, swift
- Ambito
- mobile, performance
Direzione di ricerca
Start in Sources/MapboxMaps/Location/AppleLocationProvider.swift at the accuracyAuthorization read in AppleLocationProvider.init, then trace where the default location provider is created from MapView.init. Compare the two approaches described in the issue: defer provider creation until location is used, or receive authorization through locationManagerDidChangeAuthorization(_:). Done means creating a map view no longer makes this synchronous authorization read on the main thread while location is unused.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- Xcode version: 26.6
- iOS version: 26.6.2 (the event below); the code path is the same on every iOS version
- Devices affected: iPhone 14 Plus (iPhone14,7) in this event; any device can hit it, because the call blocks on
locationd - Maps SDK Version: 11.23.1, through
@rnmapbox/maps10.3.5. The same read is still onmain(11.33.0).
Observed behavior and steps to reproduce
Creating a MapView reads CLLocationManager.accuracyAuthorization on the main thread. That getter is a synchronous XPC call to locationd. When locationd is slow to answer, the main thread blocks: our Sentry app-hang reports show 2.8–3.6 s with the main thread fully blocked.
The map never shows the user's location, and the app never asks for location permission. The read happens only because MapView.init builds the default location provider.
Steps: create a MapView on the main thread (any app; ours is a React Native app through @rnmapbox/maps). The read happens every time. The hang happens when locationd is slow, which we see in production a few times a month.
Main thread, from the app-hang report (innermost first):
mach_msg2_trap
xpc_connection_send_message_with_reply_sync
__NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__
-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]
CLGetUncertaintyScaleFactors
CLSetClientTransientAuthorizationInfo
CLClientGetLocation
CLLocationManager.accuracyAuthorization.getter
AppleLocationProvider.init
LocationDataModel.createDefault
MapView.setupManagers
MapView.commonInit
MapView.init
RNMBXMapView.createMapView
The read is Sources/MapboxMaps/Location/AppleLocationProvider.swift line 171 on main:
self.latestLocationAndAccuracyAuth = ([], locationManager.accuracyAuthorization)
Expected behavior
Creating a map view does not make a synchronous call to locationd on the main thread, at least while the map does not use location. Apple's documentation for CLLocationManager warns that its synchronous authorization reads can make the UI unresponsive when called on the main thread.
Notes / preliminary analysis
Two possible fixes:
- Create the default location provider lazily, on the first use of location (a puck, a location consumer, or
mapView.location), not inMapView.init. - Do not read
accuracyAuthorizationinAppleLocationProvider.init. Take the value fromlocationManagerDidChangeAuthorization(_:), which Core Location calls when the manager is created.
@rnmapbox/maps has a second copy of this read (its RNMBXLocationModule creates an AppleLocationProvider when the package loads). We have a patch for that side, and we will offer it to rnmapbox separately. That patch cannot reach the read in MapView.init.
Additional links and references
AppleLocationProvider.swiftline 171 onmain: https://github.com/mapbox/mapbox-maps-ios/blob/main/Sources/MapboxMaps/Location/AppleLocationProvider.swift#L171
- Lingua principale
- Swift
- Stelle
- 601
- Fork
- 198
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mapbox/mapbox-maps-ios
-
auto-triaged bug :beetle: p3 SwiftUI
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
mapbox/mapbox-maps-ios#2452 · 6 reazioni ·
-
auto-triaged bug :beetle: p2
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
mapbox/mapbox-maps-ios#2451 ·
-
auto-triaged bug :beetle: needs info p3 performance :zap:
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
mapbox/mapbox-maps-ios#2450 · 1 commento ·
-
auto-triaged bug :beetle: p1
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
mapbox/mapbox-maps-ios#2449 · 5 commenti ·
-
auto-triaged bug :beetle: p2
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
mapbox/mapbox-maps-ios#2448 ·
Tutte le issue di mapbox/mapbox-maps-ios
Issue simili
-
area: agents
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
manaflow-ai/cmux#29762 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno