Philip Dukhov
01/24/2021, 3:14 PMsuspend fun pickSystemImage(): ImageContainer =
suspendCancellableCoroutine { continuation ->
MainScope().launch {
NSLog("pickSystemImage MainScope().launch")
val imagePicker = UIImagePickerController()
NSLog("pickSystemImage 1")
// present and handle
}
}
the problem is that initializing UIImagePickerController
takes huge amount of time - around 6 secs, every time.
2021-01-24 21:56:42.439651+0700 Well[3450:1028035] pickSystemImage MainScope().launch
2021-01-24 21:56:48.593539+0700 Well[3450:1028035] pickSystemImage 1
I’ve tried reproducing this in a test project, and there it works fine.
I’ve tried switching outer scope, as well as creating scope with main context instead of MainScope, or just without switch to an other scope..
I’m out of the ideas where to look for a solutionlouiscad
01/24/2021, 8:22 PMsuspendCancellableCoroutine
at all FYI (you can refere to its doc).
You are probably looking for Dispatchers.Default { }
since it looks like you have a blocking call.Philip Dukhov
01/25/2021, 4:09 AMsuspendCancellableCoroutine
is used heresuspendCancellableCoroutine
suspend fun pickSystemImage(): ImageContainer =
Dispatchers.Main {
NSLog("pickSystemImage")
val imagePicker = UIImagePickerController()
NSLog("imagePicker created")
//…
}
Result is the same - 6 seconds to initiate the pickerlouiscad
01/25/2021, 9:34 AMUIImagePickerController()
itself, or something else in your app keeping the main thread/loop busy. Did you Google UIImagePickerController
?Philip Dukhov
01/25/2021, 9:51 AM