我正在尝试编写一个方便的函数,该函数将接受图像标识符并使用 AFNetworking 的 AFImageRequestOperation 下载图像。该函数正确下载图像,但我无法在成功块中返回 UIImage。
-(UIImage *)downloadImage:(NSString*)imageIdentifier
{
NSString* urlString = [NSString stringWithFormat:@"http://myserver.com/images/%@", imageIdentifier];
AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] imageProcessingBlock:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
NSLog(@"response: %@", response);
return image;
}
failure:nil];
[operation start];
}
该return image;
行给了我错误:
Incompatible block pointer types sending 'UIImage *(^)(NSURLRequest *__strong, NSHTTPURLResponse *__strong, UIImage *__strong)' to parameter of type 'void (^)(NSURLRequest *__strong, NSHTTPURLResponse *__strong, UIImage *__strong)'
有什么想法吗?我很想能够打电话
UIImage* photo = [downloadImage:id_12345];