how can I get the response string from failure block in AFNetworking 3.x,
In the 2.x version the way to do it was:
[manager GET:path parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dictionary_FetchResult = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSDictionary *dictionary_FetchResult = operation.responseObject;
}];
but in the 3.x version there is no operation in the returning block's parameter as shown below:
[manager POST:path parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dictionary_FetchResult = responseObject;
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];
so I was hoping if someone was able to achieve that.
I have found a solution for this which works perfectly. In swift
and Objective-C code is
Fixed some code here, properly handling optionals. Swift 3(.1)...
For Swift 3
Just do this in your failure block:-
For Swift:-
Updated for Swift 4.1
I've found solution at GitHub:
And then assign it to your manager: