我想检测目标c中的方法是否在前台或后台运行的NSThread
上调用并执行。
由于
答案 0 :(得分:3)
您可以检查当前主题是否为主要主题:
+ (BOOL)[NSThread isMainThread]
答案 1 :(得分:0)
(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..");
}
}