Progress of a Alamofire request

后端 未结 3 1660
难免孤独
难免孤独 2020-12-11 17:53

Will it be possible to show progress for

Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON)
 .responseJSON { response in
 // Do your stuf         


        
3条回答
  •  盖世英雄少女心
    2020-12-11 18:32

    The way you monitor progress in Alamofire is using the progress closure on a Request. More details on usage can be found in the README. While that example in the README demonstrates usage on a download request, it still works on a data request as well.

    The one important note is that you do not always get perfect reporting back from the server for a data request. The reason is that the server does not always report an accurate content length before streaming the data. If the content length is unknown, the progress closure will be called, but the totalExpectedBytesToRead will always be -1.

    In this situation, you can only report accurate progress if you know the approximate size of the data being downloaded. You could then use your approximate number in conjunction with the totalBytesRead value to compute an estimated download progress value.

提交回复
热议问题