美文网首页
2018-08-07

2018-08-07

作者: Gradlyarn | 来源:发表于2018-08-07 00:21 被阅读13次
    //1.创建类型为 定时器类型的 Dispatch Source
    //1.1将定时器设置在主线程
     _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
    //1.2设置定时器每一秒执行一次
    dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1ull * NSEC_PER_SEC, 0);
    //1.3设置定时器执行的动作
    dispatch_source_set_event_handler(_timer, ^{
        //在这里实现业务逻辑...
    });
    //2.启动定时器
    dispatch_resume(_timer);

相关文章

网友评论

      本文标题:2018-08-07

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