gpt4 book ai didi

ios - NSURLSession 优先级

转载 作者:可可西里 更新时间:2023-11-01 03:08:12 25 4
gpt4 key购买 nike

我正在尝试将用于从 NSOperationQueue 加载文件的旧代码移植到 NSURLSession。几乎一切都很好,但我找不到如何设置加载不同任务的优先级。有人知道 NSURLSession 是否完全支持优先级排序吗?如果是的话,你能告诉我怎么做吗?

提前致谢!

罗斯特

最佳答案

NSURLSessionTask 上有一个属性

@property float priority NS_AVAILABLE(10_10, 8_0);

它的描述说

  • Sets a scaling factor for the priority of the task. The scaling factor is a value between 0.0 and 1.0 (inclusive), where 0.0 is considered the lowest priority and 1.0 is considered the highest.
  • The priority is a hint and not a hard requirement of task performance. The priority of a task may be changed using this API at any time, but not all protocols support this; in these cases, the last priority that took effect will be used. If no priority is specified, the task will operate with the default priority
  • as defined by the constant NSURLSessionTaskPriorityDefault. Two additional priority levels are provided: NSURLSessionTaskPriorityLow and NSURLSessionTaskPriorityHigh, but use is not restricted to these.

我在可以在我们的应用程序中同时触发的 downloadTask 和 dataTask 之间使用它,并且 dataTask 永远等待下载。但这解决了问题

dataTask.priority = NSURLSessionTaskPriorityHigh;

关于ios - NSURLSession 优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23602287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com