I need to record some data/info when Alamofire called resume to start the request. (I used Swift in my project)
Is there anyway without do method_swizzling?
the timeline will be like this:
Call a request (put in request queue or execute right away) -> [custom method] -> SessionTask.resume()
I know Moya did something similar called WillSend. But I would like to know how to do it without using Moya.
Thank you.
If all you need to do is inspect various request elements you can use Alamofire 5's
EventMonitorprotocol, which is called during various lifetime events as Alamofire makes requests. There's a built inClosureEventMonitorwhich allows you to set closures for those events. For example:Please see our documentation for
ClosureEventMonitorand theEventMonitorprotocol itself.