您的位置:首页 > 其它

AFNetworking 动态修改acceptableContentTypes 设置ContentType

2017-03-13 15:20 323 查看
AFJSONResponseSerializer+Serializer.h

#import <AFNetworking/AFNetworking.h>

@interface AFJSONResponseSerializer (Serializer)

@end

AFJSONResponseSerializer+Serializer.m

#import "AFJSONResponseSerializer+Serializer.h"
#import <objc/runtime.h>

@implementation AFJSONResponseSerializer (Serializer)

+(void)load {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method ovr_initMethod = class_getInstanceMethod([self class], @selector(init));
Method swz_initMethod = class_getInstanceMethod([self class], @selector(swizzlingForSetSerializer_init));
method_exchangeImplementations(ovr_initMethod, swz_initMethod);
});

}

- (id) swizzlingForSetSerializer_init {

id swz_self = [self swizzlingForSetSerializer_init];
if (swz_self && [swz_self isKindOfClass:[AFJSONResponseSerializer class]]) {
//start  tiny
NSSet * contentSet = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/plain", @"text/html", nil];
[swz_self setValue:contentSet forKey:@"acceptableContentTypes"];
}
else {
NSLog(@"AFJSONResponseSerializer+Serializer kvc get AFJSONResponseSerializer error");
}
//
return swz_self;
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: