Skip to content

MapView.init reads CLLocationManager.accuracyAuthorization on the main thread, which can hang for seconds #2447

Open

Description

@kristojorg

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/maps 10.3.5. The same read is still on main (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:

  1. Create the default location provider lazily, on the first use of location (a puck, a location consumer, or mapView.location), not in MapView.init.
  2. Do not read accuracyAuthorization in AppleLocationProvider.init. Take the value from locationManagerDidChangeAuthorization(_:), 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

Activity

  1. added
    bug 🪲
    performance ⚡
    auto-triaged
    on Oct 26, 2026
  2. AlexandrBasan commented on Nov 17, 2026

    @AlexandrBasan

    We also have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-triagedbug 🪲p2performance ⚡

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions