今天用七牛的- (void)putData:(NSData *)data
key:(NSString *)key
token:(NSString *)token
complete:(QNUpCompletionHandler)completionHandler
option:(QNUploadOption *)option这个方法上传图片时,QNHttpManager中- (instancetype)init {
if (self = [super init]) {
_httpManager = [[AFHTTPRequestOperationManager alloc] init];
_httpManager.responseSerializer = [AFJSONResponseSerializer serializer];
// _httpManager.requestSerializer = [AFHTTPRequestSerializer serializer];
}
return self;
}添加被注释的那行代码后,不会崩溃,但是 putdata 后的回调不能调用。如果不添加这行代码,会崩溃。因为生成的request 为nil
(void)multipartPost:(NSString *)url
withData:(NSData *)data
withParams:(NSDictionary *)params
withFileName:(NSString *)key
withMimeType:(NSString *)mime
withCompleteBlock:(QNCompleteBlock)completeBlock
withProgressBlock:(QNInternalProgressBlock)progressBlock
withCancelBlock:(QNCancelBlock)cancelBlock {
NSMutableURLRequest *request = [_httpManager.requestSerializer
multipartFormRequestWithMethod:@"POST"
URLString:url
parameters:params
constructingBodyWithBlock: ^(id < AFMultipartFormData > formData) {
[formData appendPartWithFileData:data name:@"file" fileName:key mimeType:mime];
}
error:nil];
[self sendRequest:request
withCompleteBlock:completeBlock
withProgressBlock:progressBlock];
}
主要原因是_httpManager.requestSerializer 为nil 。 请问这种情况可以解决吗? 原来项目中使用了AFNetworking 。。。