Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs don't mention that on iOS geolocation needs to be done on a thread with a run loop #184

Open
heldercorreia opened this issue Feb 13, 2025 · 0 comments

Comments

@heldercorreia
Copy link

heldercorreia commented Feb 13, 2025

I'm new to iOS and expected that calling this inside a suspend function launched in Dispatchers.IO:

val geolocator = Geolocator.mobile()
val geolocatorResult = geolocator.current(priority = Priority.HighAccuracy)

would simply work on iOS just like it does on Android.
It turns out that on iOS it needs to be done like this:

var geolocatorResult
withContext(Dispatchers.Default) {    // [***]
        val geolocator = Geolocator.mobile()
        geolocatorResult = geolocator.current(priority = Priority.HighAccuracy)
}

Otherwise, the app will never return.

There is no mention of these facts in the docs, which can result in great time wasting for people in the same situation like myself.

Source: https://developer.apple.com/documentation/corelocation/cllocationmanager

[***] Using Dispatchers.Main here instead will trigger the warning:
[CoreLocation] This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first.

@heldercorreia heldercorreia changed the title Docs don't mention that on iOS geolocation needs to be done on a thread with a run loop (typical main thread) Docs don't mention that on iOS geolocation needs to be done on a thread with a run loop Feb 13, 2025
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

No branches or pull requests

1 participant