3

Is it possible to swizzle connection:didReceiveResponse: and connection:willsendrequestforauthenticationchallenge: delegate methods. If Yes, Please suggest me a way to do this. I am able to swizzle initwithrequest: method but I am not able to swizzle delegate methods.

Note: I can use nsurlconnection though it is deprecated.

Amit Srivastava
  • 1,105
  • 9
  • 18
Madhu Avinash
  • 933
  • 2
  • 8
  • 27
  • I think in generally we can asked how to swizzle the delegate methods ? @Madhu have you found any solution or workaround to achieve this ? – damithH Feb 27 '17 at 09:03

2 Answers2

-1

Use NSURLProtocal instead of swizzling, see tutorial:

https://www.raywenderlich.com/59982/nsurlprotocol-tutorial

Roy K
  • 3,319
  • 2
  • 27
  • 43
-1

It seems that you have mixed up methods of given class with methods of a protocol to be implemented by a delegate class.

NSURLConnectionDelegate is a protocol to be implemented by your code. So why would you want to swizzle a method of your own code when can simply change your code?

connection:didReceiveResponse: and connection:willSendRequestForAuthenticationChallenge can be swizzled if you specify the class that implements it (and not NSURLConnectionDelegate, which is just a protocol without implementation). But then again: why would you?

Codo
  • 75,595
  • 17
  • 168
  • 206
  • @Code, for e.g. we have a sdk, which can include many apps developed by our company. but the thing is all app already developed and use default NSURLConnection class so it easier to inject some code inside the NSURLConnection level to achieve this. The injection can add in the sdk level. – damithH Feb 27 '17 at 09:11