Afnetworking: Overriding dataTaskWithRequest:completionHandler:

Created on 30 Mar 2016  路  1Comment  路  Source: AFNetworking/AFNetworking

Hey guys,

I am trying to override dataTaskWithRequest:completionHandler:. I am following your instructions found in the documentation for AFHTTPSessionManager where it is stated:

To change the behavior of all data task operation construction, which is also used in the GET / POST / et al. convenience methods, override dataTaskWithRequest:completionHandler:.

My class subclasses AFHTTPSessionManager and in the implementation I have the dataTaskWithRequest:completionHandler: method. In its implementation I call [super dataTaskWithRequest:completionHandler:].

Anyway, the problem is that dataTaskWithRequest:completionHandler: is never called...

Could you please check whether this is a bug? If not, please provide me some instructions.

Cheers!

Most helpful comment

@sasojadrovski I was having the same issue today migrating our project to 3.x... I don't think it is an actual bug, but a problem with the documentation not being up-to-date.

In the latest AFNetworking version, all the GET, POST, etc. convenience methods don't go through dataTaskWithRequest:completionHandler: anymore. Instead, they go through the new dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:. That is the reason why your subclass's overwrite was not being called.

In order to fix it, you just need to change the implementation of your AFHTTPSessionManager subclass to overwrite dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler: instead and everything should just work as usual.

I have already opened PR #3476 to fix the documentation, so no one else falls into the same problem 馃槈

>All comments

@sasojadrovski I was having the same issue today migrating our project to 3.x... I don't think it is an actual bug, but a problem with the documentation not being up-to-date.

In the latest AFNetworking version, all the GET, POST, etc. convenience methods don't go through dataTaskWithRequest:completionHandler: anymore. Instead, they go through the new dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:. That is the reason why your subclass's overwrite was not being called.

In order to fix it, you just need to change the implementation of your AFHTTPSessionManager subclass to overwrite dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler: instead and everything should just work as usual.

I have already opened PR #3476 to fix the documentation, so no one else falls into the same problem 馃槈

Was this page helpful?
0 / 5 - 0 ratings