gpt4 book ai didi

ios - 如何使用 AFNetworking 下载文件并将其保存到文档目录?

转载 作者:IT王子 更新时间:2023-10-29 07:36:35 24 4
gpt4 key购买 nike

我正在使用 AFNetworking 库。我不知道如何下载文件并将其保存到文档目录。

最佳答案

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"..."]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"filename"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];

[operation start];

关于ios - 如何使用 AFNetworking 下载文件并将其保存到文档目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8372661/

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