-1

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.

Paul.Chou
  • 3
  • 4
  • What are you looking to do at that point? – Jon Shier Jul 03 '20 at 22:46
  • @JonShier I would like to get the info for the start time of the request or the params of the request it sends or any info related to the request about to executed. Do you have any suggestions? – Paul.Chou Jul 06 '20 at 07:27

1 Answers1

0

If all you need to do is inspect various request elements you can use Alamofire 5's EventMonitor protocol, which is called during various lifetime events as Alamofire makes requests. There's a built in ClosureEventMonitor which allows you to set closures for those events. For example:

let monitor = ClosureEventMonitor()
monitor.requestDidCompleteTaskWithError = { (request, task, error) in
    debugPrint(request)
}
let session = Session(eventMonitors: [monitor])

Please see our documentation for ClosureEventMonitor and the EventMonitor protocol itself.

Jon Shier
  • 12,200
  • 3
  • 35
  • 37