If you want a repeating timer to be called on dispatch_queue_t , use dispatch_source_create with DISPATCH_SOURCE_TYPE_TIMER :
dispatch_queue_t queue = dispatch_queue_create("com.firm.app.timer", 0); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), 20ull * NSEC_PER_SEC, 1ull * NSEC_PER_SEC); dispatch_source_set_event_handler(timer, ^{
This creates a timer that starts once every 20 seconds (the third parameter is dispatch_source_set_timer ) with a delay of one second (the fourth parameter is before dispatch_source_set_timer ).
To cancel this timer, use dispatch_source_cancel :
dispatch_source_cancel(timer);
source share