美文网首页
GCD定时器

GCD定时器

作者: 进击的小巨牛 | 来源:发表于2017-07-06 15:51 被阅读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);

    相关文章

      网友评论

          本文标题:GCD定时器

          本文链接:https://www.haomeiwen.com/subject/viwhhxtx.html