Afnetworking: AFHTTPSessionManager respondsToSelector issue with AFNetworking 3.0 & iOS 9.2

Created on 20 Dec 2015  路  6Comments  路  Source: AFNetworking/AFNetworking

Sometimes, but not always, AFHTTPSessionManager get is crashing with the following exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[xxxManager GET:parameters:progress:success:failure:]: unrecognized selector sent to instance.

Out of curiosity, I logged the following just prior to making the GET:params, etc call:

[self respondsToSelector:@selector(GET:parameters:progress:success:failure:)]
[self respondsToSelector:@selector(GET:parameters:success:failure:)]
[self respondsToSelector:@selector(POST:parameters:progress:success:failure::parameters:progress:success:failure:)]
[self respondsToSelector:@selector(POST:parameters:success:failure:)]

The answers I got were NO, YES, NO, YES. Its like the new 3.0 methods don't exist. I run pod update, seems like everything is fine. Says version 3.0.4 is being used.

The strange thing is that sometimes it works fine.

Some setup notes: this is an iPhone app with companion app. They are bouncing some data back and forth with WatchConnectivity. All of the networking calls are being done on the iPhone app. When I run the iPhone app by itself it almost always works (and when I check the respondsToSelector calls I get YES across the board). When I run the companion app, and it triggers a network call on the iPhone app is where the issues tend to occur.

Any ideas?

Most helpful comment

Sorry - I should have followed up on how I resolved the issue. It was a Xcode problem.

I was running "clean" before each "build", but somehow Xcode didn't fully clean everything properly, so somehow a version of the 2.6 framework was lying around. And occasionally the runtime was finding the 2.6 framework, and sometimes the 3.0 framework. Curious that it was picking up the 2.6 framework more often when the iPhone app was launched in the background from the Watch app via WatchConnectivity.

Anyway, a "clean build folder" fixed the issue, and it hasn't reappeared.

All 6 comments

This is interesting... I wonder if this is related to #3276 ?

I would expect the third example to return NO there (unless thats just a typo on your part).

Do you have a simple example you could push up that demonstrates the issue?

Sorry - I should have followed up on how I resolved the issue. It was a Xcode problem.

I was running "clean" before each "build", but somehow Xcode didn't fully clean everything properly, so somehow a version of the 2.6 framework was lying around. And occasionally the runtime was finding the 2.6 framework, and sometimes the 3.0 framework. Curious that it was picking up the 2.6 framework more often when the iPhone app was launched in the background from the Watch app via WatchConnectivity.

Anyway, a "clean build folder" fixed the issue, and it hasn't reappeared.

Thanks @jamesmattis!

I got same Error:
[AFHTTPSessionManager GET:parameters:progress:success:failure:]: unrecognized selector sent to instance after AFNetworking 3.0 Migration and solved it with Clean Build Folder.

I think, there is need to add this recommendation (Make "Clean Build Folder" to prevent the errors) to AFNetworking 3.0 Migration Guide, as XCode still has such bug.

I fix it by removing the Build Finder and then install pods
if you meet not found for lAFNetworking you can choose another simulators

Was this page helpful?
0 / 5 - 0 ratings