jac*_*cky -2 objective-c ios afnetworking
我想创建一个从Internet下载任何文件并存储在文件夹中的应用程序.我在谷歌和这个网站搜索,我明白使用AFNetworking更好.在这个框架中,我可以显示progessViewshow下载状态.
我是AFNetworking的新手,我希望你指导我,并告诉我如何使用AFNetworking创建一个下载文件并显示progessView状态下载的应用程序代码.
Lit*_*T.V 11
这里的代码进度是使用的UIProgressview
filepath:保存文件的路径[Documents目录]
进口
#import <AFNetworking/AFNetworking.h>
Run Code Online (Sandbox Code Playgroud)
并下载
progress.progress = 0.0;
currentURL=@"http://www.selab.isti.cnr.it/ws-mate/example.pdf";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]];
AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MY_FILENAME_WITH_EXTENTION.pdf"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
progress.progress = (float)totalBytesRead / totalBytesExpectedToRead;
}];
[operation setCompletionBlock:^{
NSLog(@"downloadComplete!");
}];
[operation start];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5953 次 |
| 最近记录: |