我想为 api 调用制作进度条并以成功结束,我正在使用 AFNetworking 3.0 版本。
我执行以下代码来衡量进度。
NSURLSessionDataTask *obj = [manager POST:UrlForGetAllCalEntry parameters:jsonDict progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if ([[responseObject valueForKey:@"code"] integerValue] == 200)
{
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TRAVALARMMANAGER setMessage:error.localizedDescription withView:[APPDELEGATE window] textColor:txtMsgColor bgColor:bgMsgColor];
NSLog(@"Error: %@", error);
}];
[manager setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
if (dataTask.countOfBytesExpectedToReceive == NSURLSessionTransferSizeUnknown)
return;
if (dataTask != obj)
return;
NSUInteger code = [(NSHTTPURLResponse *)dataTask.response statusCode];
if (!(code> 199 && code < 400))
return;
long long bytesReceived = [dataTask countOfBytesReceived];
long long bytesTotal = [dataTask countOfBytesExpectedToReceive];
NSLog(@"... %lld/%lld",
bytesReceived,
bytesTotal);
}];
但是方法从
如果(dataTask.countOfBytesExpectedToReceive == NSURLSessionTransferSizeUnknown)返回;
此语句始终返回 true。我不明白为什么?. 我还打印了标题,它有“接触长度”选项。