五种优先级的不同使用场景
The following Quality of Service (QoS) classifications are used to
indicate to the system the nature and importance of work.
They are used by the system to manage a variety of resources.
Higher QoS classes receive more resources than
lower ones during resource contention
> * NSQualityOfServiceUserInteractive 表示用户交互任务,任务优先级高
> * NSQualityOfServiceUserInitiated 用户发起的需要立即得到回应的任务,优先级高
> * NSQualityOfServiceUtility 不需要立刻返回结果的任务,执行时间稍长。比如下载图片,数据请求
> * NSQualityOfServiceBackground 后台任务,对用户不可见,比如数据备份。任务的时间比较长
> * NSQualityOfServiceDefault 默认优先级任务,处于UserInitiated和Utility之间
创建指定优先级的串行队列的方式:
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
return dispatch_queue_create("sindrilin.com.user_interactive", attr);
以上内容参考链接
网友评论