首先 宏定义
static dispatch_source_t _sourceTimer;
然後zai需要的地方設置
//创建全局队列
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//使用全局队列创建计时器
_sourceTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
//定时器延迟时间
NSTimeInterval delayTime = 1.0f;
//定时器间隔时间
NSTimeInterval timeInterval = 100.0f;
//设置开始时间
dispatch_time_t startDelayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime * NSEC_PER_SEC));
//设置计时器
dispatch_source_set_timer(_sourceTimer,startDelayTime,timeInterval*NSEC_PER_SEC,NSEC_PER_SEC);
//执行事件
dispatch_source_set_event_handler(_sour