NSURLSession delegate and completionHandler

前端 未结 2 1029
日久生厌
日久生厌 2021-01-05 18:14

I am using NSURLSession + NSURLDownloadTask with completionHandler:

[session downloadTaskWithURL:downloadURL completionHandler:^(NSURL *location, NSURLRespon         


        
2条回答
  •  我在风中等你
    2021-01-05 18:16

    From the documentation:

    NSURLSession returns data in one of two ways, depending on the methods you call:

    • To a completion handler block that returns data to your app when a transfer finishes successfully or with an error.
    • By calling methods on your custom delegate as the data is received.

    One of two ways. Either use the completion handler (if all you want is to be notified at the end) or use the delegate methods (if you want full information as you go). Not a problem. It's not like the delegate methods are hard to use or anything; it's probably just about always better to use them.

提交回复
热议问题