Skip to content

fix(ios): resolve requestPermissions for geolocation once the user answers - #183

Open
andredestro wants to merge 1 commit into
mainfrom
fix/RMET-5551/geolocation-request-permissions
Open

andredestro wants to merge 1 commit into
mainfrom
fix/RMET-5551/geolocation-request-permissions

Conversation

@andredestro

Copy link
Copy Markdown
Contributor

Description

BackgroundRunner.requestPermissions({ apis: ['geolocation'] }) never resolves on iOS. The location dialog is shown and answered, but the promise stays pending (the console stops at geolocation requested...).

requestPermissions runs inside a Task, so CapacitorGeolocation creates its CLLocationManager on a Swift concurrency thread. Core Location delivers delegate callbacks on the run loop of the thread that created the manager, and that thread has no run loop, so locationManagerDidChangeAuthorization never fires and the continuation is never resumed.

Changes:

  • The permission request now uses a CLLocationManager created on the main thread, so its delegate callbacks are delivered.
  • locationManagerDidChangeAuthorization ignores the initial callback while the status is still notDetermined (it fires as soon as the delegate is set) and resumes only once the user has answered.

Tracked in RMET-5551.

Verification

  • On an iPhone 16 Pro Max with iOS 27.0.1, from a fresh install (status notDetermined): requestPermissions now resolves after the user answers, logging geolocation requested...done and returning {"geolocation":"granted","notifications":"granted"}. Before this change it never resolved.
  • The device test used next with this same patch applied, because the main example app can't launch with the iOS 27 SDK (it doesn't use UIScene). The code in this file is the same on both branches, apart from formatting.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant