dispatch_source_t

dispatch_source_t的作用:监听某些事件,当这些事件发生的时候,他就会把这些事件的回调的block提交到某些队列上变执行。

@abstract

 * Creates a new dispatch source to monitor low-level system objects and auto-

 * matically submit a handler block to a dispatch queue in response to events. 

 

所以使用 dispatch_source_t分为三步:

1.创建dispatch_source_create(param1,param2,param3,param4)

参数解释:

    param1:监听的事件类型,比如:DISPATCH_SOURCE_TYPE_TIMER,DISPATCH_SOURCE_TYPE_SIGNAL等

    parma4:当事件发生时,指定回调block放置的队列

2.设置dipatch_source_t的属性

比如:dispatch_set_timer(param1,param2,param3,param4)

参数解释:

    param1: dipatch_source_t变量  

    param3:时间间隔 

3.设置dipatch_source_t的回调block

dispatch_source_set_event_handler(param1,param2)

   param1: dipatch_source_t变量

   param2:回调的block

4.启动 dipatch_source_t

   resume()

5.取消

   cancel() 

 

 

posted @ 2015-11-24 20:34  Sunny孙宁  阅读(457)  评论(0编辑  收藏  举报