I want to make progress bar for api calling and end with success and i am using the AFNetworking 3.0 version.
I do the following code for measure the progress.
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);
}];
But method return from
if (dataTask.countOfBytesExpectedToReceive == NSURLSessionTransferSizeUnknown) return;
This statement always return true. I don't understand why? . I also print the header and it has "contact length" option.