How do I use NSOperationQueue with NSURLSession?

前端 未结 7 957
别跟我提以往
别跟我提以往 2020-12-04 06:48

I\'m trying to build a bulk image downloader, where images can be added to a queue on the fly to be downloaded, and I can find out the progress and when they\'re done downlo

相关标签:
7条回答
  • 2020-12-04 07:16

    With NSURLSession you don't manually add any operations to a queue. You use the method - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request on NSURLSession to generate a data task which you then start (by calling the resume method).

    You are allowed to provide the operation queue so you can control the properties of the queue and also use it for other operations if you wanted.

    Any of the usual actions you would want to take on a NSOperation (i.e. start, pause, stop, resume) you perform on the data task.

    To queue up 50 images to download you can simply create 50 data tasks which the NSURLSession will properly queue up.

    0 讨论(0)
提交回复
热议问题