gpt4 book ai didi

iphone - AFNetworking 检查进度

转载 作者:可可西里 更新时间:2023-11-01 06:17:46 25 4
gpt4 key购买 nike

我正在使用 AFNetworking 框架下载文件并将它们写入本地文件系统。

但由于文件可能很大,我想添加一个 UIProgressView,但我似乎找不到任何可以随进度更新的方法。

我看到有人在谈论 setProgressBlock,但我在文档中找不到任何相关信息:http://afnetworking.org/Documentation/Classes/AFHTTPRequestOperation.html

有没有办法做到这一点?我只是使用 AFHTTPRequestOperation 下载文件。

最佳答案

引用以下代码。这是使用 AFNetworking 代码下载的一些文件。

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://blahblah.com/blahblah.mp3"]];
AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [paths objectAtIndex:0] stringByAppendingPathComponent:@"blahblah.mp3"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead)
{
myProgressView.progress = (float)totalBytesRead / totalBytesExpectedToRead;
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"downloadComplete!");
}];
[operation start];

关于iphone - AFNetworking 检查进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11985279/

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