我们只使用AFNetworking来加载这样的图像:
[thumbnailImage setImageWithURL:_item.thumbnailUrl];
它工作正常。但现在我们已经停止了已经停止工作的项目的其余部分。它只是显示背景颜色。所以我尝试使用它并加载占位符但从不加载图像。
UIImage* placeholder = [UIImage imageNamed:@"placeholder"];
[thumbnailImage setImageWithURL:_item.thumbnailUrl placeholderImage:placeholder];
我以为我可以看到问题是什么,所以我试过了:
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:_item.thumbnailUrl cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
[thumbnailImage setImageWithURLRequest:urlRequest placeholderImage:[UIImage imageNamed:@"placeholder"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
NSLog(@"Loaded Image");
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
{
NSLog(@"Failed to load Image");
}];
似乎它没有获得它所期望的返回类型。它说Expected content type image/png, got binary/octet-stream
我从亚马逊S3中提取图像,所以我不知道我是否可以控制该类型。
答案 0 :(得分:3)
我无法更改数据类型,因此我通过将以下文件添加到项目中来覆盖AFNetworking中的acceptableContentTypes
方法。
<强> AFImageRequestOperation + OctetMIMEType.h 强>
//
// AFImageRequestOperation+OctetMIMEType.h
// iQ.fileShare
//
// Created by Poole, Patrick on 4/25/13.
//
//
#import "AFImageRequestOperation.h"
@interface AFImageRequestOperation (OctetMIMEType)
@end
<强> AFImageRequestOperation + OctetMIMEType.m 强>
//
// AFImageRequestOperation+OctetMIMEType.m
// iQ.fileShare
//
// Created by Poole, Patrick on 4/25/13.
//
//
#import "AFImageRequestOperation+OctetMIMEType.h"
@implementation AFImageRequestOperation (OctetMIMEType)
+ (NSSet *)acceptableContentTypes {
return [NSSet setWithObjects:@"binary/octet-stream",@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon" @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
}
@end
答案 1 :(得分:0)
AFNetworking提供了一种在1.3.3中添加可接受内容类型的方法,我不确定其他版本是否支持此
[AFImageRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@"binary/octet-stream", nil]];