NSURLConnection download large file (>40MB)

后端 未结 4 878
刺人心
刺人心 2020-12-02 21:10

I need to download large file (i.e. > 40MB) to my application from server, this file will be ZIP or PDF. I achieved it using NSURLConnection, that works wel

4条回答
  •  情话喂你
    2020-12-02 22:03

    If you're willing to use asi-http-request, it's much, much easier.

    Check out https://github.com/steipete/PSPDFKit-Demo for a working example with asi.

    It's about as easy as this:

        // create request
        ASIHTTPRequest *pdfRequest = [ASIHTTPRequest requestWithURL:self.url];
        [pdfRequest setAllowResumeForFileDownloads:YES];
        [pdfRequest setNumberOfTimesToRetryOnTimeout:0];
        [pdfRequest setTimeOutSeconds:20.0];
        [pdfRequest setShouldContinueWhenAppEntersBackground:YES];
        [pdfRequest setShowAccurateProgress:YES];
        [pdfRequest setDownloadDestinationPath:destPath];
    
        [pdfRequest setCompletionBlock:^(void) {
            PSELog(@"Download finished: %@", self.url);
    
            // cruel way to update
            [XAppDelegate updateFolders];
        }];
    
        [pdfRequest setFailedBlock:^(void) {
            PSELog(@"Download failed: %@. reason:%@", self.url, [pdfRequest.error localizedDescription]);
        }];
    

提交回复
热议问题