Search code examples
iosbackgroundnsthread

Detect if method is called in background / foreground


I would like to detect if a method in objective c is called and executing on NSThread that is running on foreground or background.

Thanks


Solution

  • You can check whether the current thread is the main one with:

    + (BOOL)[NSThread isMainThread]