[UIApplication applicationState] should not run in background task

Hi,


I got this message from xcode "Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]". I know this message can't be mitigated by disabling Main Thread Checker from Xcode, but it doesn't mean the risk is gone.


Is there any better way In background task to get current application state instead of calling UIApplication.shared.applicationState?

How are you calling the application state ?


Did you try just wrap it inside DispatchQueue.main.async


                DispatchQueue.main.async {
                    // Call the application state
                }

You can't read data from a dispatch_async

Keep track of the state yourself via delegate methods.

What he said, in Objective C:


   dispatch_async(dispatch_get_main_queue(), ^{

        // your code is causing a call to [UIApplication applicationState]
        //      place that code here 
   });

I just wanna get current app state, and after that I don't want my other code run in main queue.

Yes you do.

[UIApplication applicationState] should not run in background task
 
 
Q