美文网首页
使用 AFNetworking 下载文件

使用 AFNetworking 下载文件

作者: 骑行怪状 | 来源:发表于2016-03-31 17:17 被阅读570次

    首先需要通过终端 pod 导入

    `NSURLSessionConfiguration*configuration = [NSURLSessionConfigurationdefaultSessionConfiguration];AFURLSessionManager *manager = [[AFURLSessionManageralloc]initWithSessionConfiguration:configuration];NSURL*URL = [NSURLURLWithString:@"http://example.com/download.zip"];NSURLRequest*request = [NSURLRequestrequestWithURL:URL];NSURLSessionDownloadTask*downloadTask = [managerdownloadTaskWithRequest:requestprogress:nildestination:^NSURL*(NSURL*targetPath,NSURLResponse*response) {NSURL*documentsDirectoryURL = [[NSFileManagerdefaultManager]URLForDirectory:NSDocumentDirectoryinDomain:NSUserDomainMaskappropriateForURL:nilcreate:NOerror:nil];return[documentsDirectoryURLURLByAppendingPathComponent:[responsesuggestedFilename]];}completionHandler:^(NSURLResponse*response,NSURL*filePath,NSError*error) {NSLog(@"File downloaded to:%@", filePath);}];[downloadTaskresume];`

    相关文章

      网友评论

          本文标题:使用 AFNetworking 下载文件

          本文链接:https://www.haomeiwen.com/subject/segelttx.html