I have a function that must be called from a non-main thread. In that thread, I am trying to determine status bar orientation like this:
let currentInterfaceOrientation = UIApplication.shared.statusBarOrientation
But I obviously get a run time warning like this.
UIApplication.statusBarOrientation() must be used from main thread only
My question is how to determine status bar orientation on secondary thread if you need it? Using DispatchQueue.main.sync is the right way but is risky for the reasons of potential deadlocks.
var currentInterfaceOrientation = UIInterfaceOrientation.landscapeLeft
DispatchQueue.main.sync {
currentInterfaceOrientation = UIApplication.shared.statusBarOrientation
}
What are the safe ways here using Swift?
Add the orientation as an argument to this function.