I subclassed the AFHTTPSessionManager according to the best practice for iOS 8 (instead of the AFHTTPOperationManager that I used before).
I can grab NSHTTPURLResponsefrom task(except that it has no body, only headers), and the callback returns serialized responseObject, which is good.
Sometimes I need to write a response as a string or display it in a text box - is there no way to do this initially using SessionManager? OperationManager allowed you to refer to the original response as an NSString:
operation.responseString;
I suppose I could compress the serialized requestObject, but this seems like a lot of extra overhead and won't help if the response object is not valid JSON.
Here is my subclass singleton:
@implementation MyAFHTTPSessionManager
+ (instancetype)sharedManager {
static id instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
And then, to make a simple GET (which I added to the block method), I can do:
[[MyAFHTTPSessionManager sharedManager] GET:_url parameters:queryParams success:^(NSURLSessionDataTask *task, id responseObject) {
completion(YES, task, responseObject, nil);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
completion(NO, task, nil, error);
}];
source
share