download in the A.asi framework
1. Implementation stepsIn the actual development, if you want to use the ASI framework to download files on the server, just perform the following simple steps. (1) Create the Request object;
(2) Set the path to save the downloaded file;
(3) Network request (asynchronous) to send the download file.
Following the steps above, the program automatically turns on the asynchronous thread, writing data to the specified file path at 1.1 points, and no matter how large a file is downloaded, it does not consume a lot of memory space. The ASI framework is based on the underlying cfnoteworking and has a good performance. Of course, you can also set blocks, or listen to the progress of the download. Automatically uses the progress agent method to get the download progress using "Write on edge" setprogress
1 //2 //VIEWCONTROLLER.M3 //Asidownloaddemo4 //5 //Created by Hellovoidworld on 15/1/28.6 //Copyright (c) 2015 Hellovoidworld. All rights reserved.7 //8 9 #import "ViewController.h"Ten #import "ASIHTTPRequest.h" One A @interfaceViewcontroller () - -@property (nonatomic, strong) ASIHTTPRequest *request; the -@property (Weak, nonatomic) Iboutlet Uiprogressview *Progressview; - --(ibaction) startdownloading; + - @end + A @implementationViewcontroller at -- (void) Viewdidload { - [Super Viewdidload]; - //additional setup after loading the view, typically from a nib. - } - in- (void) Dealloc { - [Self.request Cleardelegatesandcancel]; toSelf.request =Nil; + } - the-(ibaction) startdownloading { * //1. Create a request $Nsurl *url = [Nsurl urlwithstring:@"Http://192.168.0.21:8080/MyTestServer/images/images.zip"];Panax NotoginsengSelf.request =[ASIHTTPRequest Requestwithurl:url]; - the //2. Set the file storage path +NSString *cachepath =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) lastobject]; ANSString *filepath = [CachePath stringbyappendingpathcomponent:@"Images.zip"]; theSelf.request.downloadDestinationPath =FilePath; + - //3. Set up Download Agent $ //because just download Agent method has a setprogress, you can directly use the Progressview setprogress, directly control the progress bar $Self.request.downloadProgressDelegate =Self.progressview; - - //4. Support Breakpoint Download theSelf.request.allowResumeForFileDownloads =YES; - WuyiSelf.request.completionBlock = ^{ theNSLog (@"Download complete!"); - }; Wu - //5. Sending the request About [Self.request startasynchronous]; $ } - - #pragmaMark-asiprogressdelegate - /** Download Progress Agent Method*/ A //-(void) setprogress: (float) newprogress { + //self.progressView.progress = newprogress; the //} - $ @end
2. Breakpoint DownloadASI File Download There is also a property to set whether breakpoint downloads are supported. Set the code to support the breakpoint download as follows:
Request.allowresumeforfiledownloads=yes;
In this case, for example, a file has been downloaded from 30 to the sandbox of the program, this time canceled the download. The next time you click to download the file, it will download the remaining 70 and 1.1-point writes to the sandbox.
Tip: The code to cancel the download is: [Request Cleardelegatesandcancel];
[IOS Multithreading & Networking-2.10]-ASI Framework download file