阿神2017-04-17 17:01:04
Create [NSTimer timerxxx]
timer using that method, then:
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
Lou also talked about the problem of run loop in this thread
迷茫2017-04-17 17:01:04
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(dealTimerClick) userInfo:nil repeats:YES];
You can look at the description of this method in the document:
Creates and returns a new NSTimer object and schedules it on the current run loop in the default mode.
There is no problem with the main thread because the main thread has its own run loop, so I think you need to configure the run loop yourself when running on the child thread.
大家讲道理2017-04-17 17:01:04
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(_source, delay, interval * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(source, ^{
[weakTarget fire];
});
dispatch_resume(source);
Remember to add semaphore control in the fire method