Skip to content

Commit

Permalink
Fixed the case were we swizzle ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielDemarco committed Feb 12, 2025
1 parent 2dc12da commit f56428d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Sources/EmbraceCore/Capture/Network/URLSessionCaptureService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ struct URLSessionInitWithDelegateSwizzler: URLSessionSwizzler {
return originalImplementation(urlSession, Self.selector, configuration, delegate, queue)
}

guard !(proxiedDelegate is EMBURLSessionDelegateProxy) else {
if let newDelegate = proxiedDelegate as? EMBURLSessionDelegateProxy,
let originalDelegate = newDelegate.originalDelegate as? URLSessionDelegate {
return originalImplementation(urlSession, Self.selector, configuration, originalDelegate, queue)
} else {
return originalImplementation(urlSession, Self.selector, configuration, delegate, queue)
}
return originalImplementation(urlSession, Self.selector, configuration, delegate, queue)
}

let newDelegate = EMBURLSessionDelegateProxy(delegate: proxiedDelegate, handler: handler)
let session = originalImplementation(urlSession, Self.selector, configuration, newDelegate, queue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ - (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)
if ([self.originalDelegate respondsToSelector:@selector(URLSession:didBecomeInvalidWithError:)]) {
[self.originalDelegate URLSession:session didBecomeInvalidWithError:error];
}
self.originalDelegate = nil;
}

#pragma mark - NSURLSessionTaskDelegate Methods
Expand Down

0 comments on commit f56428d

Please sign in to comment.