GCD定时器
2017-07-06 本文已影响8人
进击的小巨牛
//GCD定时器
dispatch_source_t timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 15ull*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1ull*NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
NSLog(@"wakeup");
dispatch_source_cancel(timer);
});
dispatch_source_set_cancel_handler(timer, ^{
NSLog(@"cancel");
dispatch_release(timer);
});
//启动
dispatch_resume(timer);