我正在使用HTTP GET方法开发AFNetworking 3.0。我能够获得成功的响应,但不会调用下载进度块。以下是我的代码。
AFHTTPSessionManager *op = [AFHTTPSessionManager manager];
op.responseSerializer = [AFJSONResponseSerializer serializer];
NSURLSessionDataTask *dataTask = [op dataTaskWithRequest:request
uploadProgress:nil downloadProgress:^(NSProgress * _Nonnull uploadProgress) {
[op setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
if (dataTask.countOfBytesExpectedToReceive == NSURLSessionTransferSizeUnknown) {
return;
}
NSUInteger code = [(NSHTTPURLResponse *)dataTask.response statusCode];
if (!(code > 199 && code < 400)) {
return;
}
long long bytesReceived = [dataTask countOfBytesReceived];
long long bytesTotal = [dataTask countOfBytesExpectedToReceive];
progression(code, bytesReceived, bytesTotal);
}];
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
long statuscode = (long)[httpResponse statusCode];
}];
[dataTask resume];