MBProgressHUD with NSURLConnection

后端 未结 3 1810
予麋鹿
予麋鹿 2020-12-15 14:26

I was trying to use MBProgressHUD with NSURLConnection.

The example in Demo project of MBProgressHUD reports:

- (IBAction)showURL:(id)sender {
    NS         


        
相关标签:
3条回答
  • 2020-12-15 15:05

    I solved the problem this way, switching from NSURLRequest to NSMutableURLRequestand setting the value none to the encoding (previously in gzip)

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:anURL];
    [request addValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
    
    0 讨论(0)
  • 2020-12-15 15:16

    In swift i solved this issue by sending empty string in Accept-Encoding header field of the url request. Total bytes expected to write now returns the actual size in bytes of the file being downloaded.

    var request = URLRequest(url: url)
    request.addValue("", forHTTPHeaderField: "Accept-Encoding")
    
    0 讨论(0)
  • 2020-12-15 15:18

    You should check the value of [response expectedContentLength] in didReceiveResponse.

    A http server can omit the "Content-Length" header and use "Transfer-Encoding: chunked" instead. In that case the content length is not known a priori and [response expectedContentLength] returns NSURLResponseUnknownLength (which is -1)`.

    I could imagine that setting HUD.progress to a negative value causes the CGPathAddArc console messages.

    According to the documentation, it can also happen that the accumulated currentLength becomes larger than the expected response length, so you should check for that also.

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