gpt4 book ai didi

ios - AFNetworking 3.0 无法下载图像

转载 作者:可可西里 更新时间:2023-11-01 05:04:19 25 4
gpt4 key购买 nike

我正在尝试使用 AFNetworking 3.0 以这种方式下载图像:

- (UIImage *) loadImage:(NSString *) link
{
__block UIImage *image = [UIImage imageNamed:@"no_user_profile_pic.png"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFImageResponseSerializer serializer];
[manager GET:[link stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]
parameters:nil
progress:nil
success:^(NSURLSessionTask *task, id responseObject) {
image = (UIImage *) responseObject;
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Load Image error - %@", [error description]);
}];
return image;
}

每次我收到此错误时:

*** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:], /Users/.../AFNetworking/AFURLRequestSerialization.m:353

我不知道我做错了什么。发生了什么错误?

最佳答案

如果您使用 AFNetworking 3.0,您需要添加头文件 AFImageDownloader.h:

#import <AFNetworking/AFImageDownloader.h>

并使用方法downloadImageForURLRequest:

    NSString *stringVideo = [NSString stringWithFormat:@"https:%@", your link];
AFImageDownloader *downloader = [[AFImageDownloader alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: stringVideo]];
[downloader downloadImageForURLRequest:request success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) {

NSLog(@"Succes download image");

}failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {

NSLog(@"Error download image");
}];

关于ios - AFNetworking 3.0 无法下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007238/

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