This is baffling me. I have hooked class methods on NSURLConnection
with no problems but I am stuck with +[NSURLSession sessionWithConfiguration:delegate:delegateQueue:]
.
I even tried logging all the class methods with class_copyMethodList (object_getClass([NSURLSession class]), &count);
and the class method is actually there:
sessionWithConfiguration:delegate:delegateQueue:
initialize
And the weird thing is the hook does get called so I think we got it right. Calling %orig()
and just passing the parameters down yields:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSURLSession sessionWithConfiguration:delegate:delegateQueue:]: unrecognized selector sent to class 0x1919932b8'
Here's the hook:
+ (NSURLSession *)sessionWithConfiguration:(NSURLSessionConfiguration *)configuration
delegate:(id<NSURLSessionDelegate>)delegate
delegateQueue:(NSOperationQueue *)queue
{
NSURLSession *origResult = %orig(configuration, delegate, queue);
return origResult;
}
Am I missing anything?
Setup details: rpetrich's Theos Mac OS X 10.9.5 iPad Air 1 iOS 7.1.2
The problem here is related to NSURLSession being a class cluster. While the code in OP successfully hooked the class method,
%orig
needs to call on the real class name. So to make it work, this hook has to be placed under%hook __NSCFURLSession
. The real class name might be different for your case.Try this code...
delegateQueue Specifies the NSOperationQueue. if your code requires delegateQueue instead of nil you should declare queue.