kean / Pulse

Network logger for Apple platforms
https://pulselogger.com
MIT License
6.32k stars 302 forks source link

URLSessionProxyDelegate.enableAutomaticRegistration swizzling troubles with Instabug SDK #220

Closed jgodonQobuz closed 11 months ago

jgodonQobuz commented 1 year ago

Hi !

I hope you're doing well 👍

I'm using your great library with the new macOS app that is very useful to us to monitor network calls and speed troubles of our app across the world.

Unfortunately, I'm experimenting conflicts between Pulse lib and Instabug lib... Instabug bugs reporter seems to be swizzled by Pulse... As we're using both in our project this is very sad because we've to choose between user feature bugs reporting and network log monitoring...

I'll let guys from Instabug come to you with more details but I think this is the function at the origin of this issue :

public extension URLSessionProxyDelegate {
    /// Enables automatic registration of `URLSessionProxyDelegate`. After calling this method, every time
    /// you initialize a `URLSession` using `init(configuration:delegate:delegateQueue:))` method, the
    /// delegate will automatically get replaced with a `URLSessionProxyDelegate` that logs all the
    /// needed events and forwards the methods to your original delegate.
    static func enableAutomaticRegistration(logger: NetworkLogger = .init()) {
        sharedLogger = logger
        if let lhs = class_getClassMethod(URLSession.self, #selector(URLSession.init(configuration:delegate:delegateQueue:))),
           let rhs = class_getClassMethod(URLSession.self, #selector(URLSession.pulse_init(configuration:delegate:delegateQueue:))) {
            method_exchangeImplementations(lhs, rhs)
        }
    }
}

I hope a solution will be found because these two tools are so great !

Best wishes

Jeremie

kean commented 11 months ago

There are multiple ways to integrate Pulse, ranging from some to no swizzling required. Please consider using a different approach.