首页 > 解决方案 > Alamofire 5 - file download execution time (Swift 5)

问题描述

I've just updated my project from Alamofire 4 to Alamofire 5 and updating code where required, but there's one that I can't find any help in the reference docs or previous posts regarding the time taken to download.

In previous version I used "response.timeline.totalDuration it provides time interval in seconds from the time the request started to the time response serialization completed." from (Checking response Time of API in iOS using Swift 3?).

Any help to get method for Alamofire 5 would be greatly appreciated.

标签: iosswiftalamofire

解决方案


You should now use response.metrics.taskInterval. This returns a DateInterval describing how long it took from the initiation of the network request to the completion. More info: https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#download-progress

If you want to get this duration in seconds try response.metrics.taskInterval.duration


推荐阅读