iOS定时器取消,用在socket断线重连

 1.创建

static dispatch_source_t _reconTimer;

dispatch_source_cancel(_timer);

        NSTimeInterval period =5;//设置时间间隔

        dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

        _reconTimer =dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,0, queue);

        dispatch_source_set_timer(_reconTimer,dispatch_walltime(NULL,0), period * NSEC_PER_SEC,0);

        dispatch_source_set_event_handler(_reconTimer, ^{

//方法

        });

        dispatch_resume(_reconTimer);

2.取消


                dispatch_source_cancel(_reconTimer);


猜你喜欢

转载自blog.csdn.net/develop_csdn/article/details/78749166
今日推荐