要写一个应用,用来接受图片标示符,并且使用 AFNetworking 的 AFImageRequestOperation 下载图片。
目前下载已经成功了,但是在block中无法返回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];