gpt4 book ai didi

ios - 通过 AFNetworking 下载时显示文件的百分比

转载 作者:行者123 更新时间:2023-11-28 20:10:48 25 4
gpt4 key购买 nike

我可以使用下面的代码下载任何文件(我从 Github AFNetworking 教程页面获取)。我的问题是,如何在下载时在标签中显示下载文件的百分比?

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:@"http://example.com/download.zip"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
return [documentsDirectoryPath URLByAppendingPathComponent:[targetPath lastPathComponent]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
}];
[downloadTask resume];

最佳答案

尝试 AFDownloadRequestOperation - AFNetworking 的渐进式下载操作

关于ios - 通过 AFNetworking 下载时显示文件的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20336433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com