0

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

radj
  • 4,360
  • 7
  • 26
  • 41

2 Answers2

0

Try this code...

+ (NSURLSession *) sessionWithConfiguration: (NSURLSessionConfiguration *) configuration delegate: (id) delegate delegateQueue: (NSOperationQueue *) queue
{
     NSURLSession *  session  = [ NSURLSession  SessionWithConfiguration : Configuraion  
                            delegate : self 
                       DelegateQueue : nil ];
}

delegateQueue Specifies the NSOperationQueue. if your code requires delegateQueue instead of nil you should declare queue.

vishnu
  • 715
  • 9
  • 20
  • Problems: 1. With the case used, `SessionWithConfiguration` `DelegateQueue`, this does not compile because this method is not anywhere or is it supposed to be in another header? 2. If you meant `sessionWithConfiguration` `delegateQueue`. It will end up in a call that is forever recursive because it just calls itself. 3. self cannot be used in a class method, only in an instance method. – radj Oct 28 '14 at 08:22
  • just go through this link http://qiita.com/aKentaKoyama/items/96a979ab3a140e7b39ec – vishnu Oct 28 '14 at 09:05
0

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.

Community
  • 1
  • 1
radj
  • 4,360
  • 7
  • 26
  • 41