I have created NSURLConnection method swizzling for sendSynchronousRequest, however its not been working below is my code. Whenever I am trying to call this from main function, its crashing.
let originalRequestSyncSelector = #selector(self.sendSynchronousRequest(_:returning:))
let swizzledRequestSyncSelector = #selector(self.swizzSendSynchronousRequest(_:returning:error:))
let originalSyncRequestMethod = class_getClassMethod(self, originalRequestSyncSelector)
let swizzledSyncRequestMethod = class_getInstanceMethod(self, swizzledRequestSyncSelector)
if originalSyncRequestMethod == nil || swizzledSyncRequestMethod == nil {
return
}
method_exchangeImplementations(originalSyncRequestMethod!, swizzledSyncRequestMethod!)
@objc func swizzSendSynchronousRequest(_ request: NSURLRequest?, returning response: URLResponse?, error: Error?) -> Data? {
var tempData: Data?
print("Inside Sync Swizzled Method")
print("------------\(String(describing: request))")
return tempData
}