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
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
You can check whether the current thread is the main one with:
+ (BOOL)[NSThread isMainThread]
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//this thread called method in background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[self callBackMethod];
});
//this method call work with main thread
[self callBackMethod];
}
-(void)callBackMethod
{
if ([NSThread isMainThread]) {
NSLog(@"main thread....");
}else
{
NSLog(@"background thread..");
}
}