Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels