diff --git a/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift b/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift index 6e152f9dd..6a49334ad 100644 --- a/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift +++ b/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift @@ -32,6 +32,31 @@ extension URLSession { // `cap_make(configuration:delegate:delegateQueue)` was used to replace the implementation of // `URLSession.init(configuration:delegate:delegateQueue)` so the call below calls the original // initializer. + + if delegate != nil { + // Proxying delegates of some 3rd party frameworks leads to crashes. Disable proxying for + // problematic classes. + // Refer to the following GitHub comments for more details: + // * https://github.com/google/gtm-session-fetcher/issues/190#issuecomment-604205556 + // * https://github.com/google/gtm-session-fetcher/issues/190#issuecomment-604757154 + let disabledDelegateClassNames = [ + "GMPx_GTMSessionFetcherService", // GooglePlaces + "GTMSessionFetcherService", // GTMSessionFetcher + ] + + let shouldDisableProxying = disabledDelegateClassNames + .compactMap { NSClassFromString($0) } + .contains { delegate?.isKind(of: $0) == true } + + if shouldDisableProxying { + return Self.cap_makeSession( + configuration: configuration, + delegate: delegate, + delegateQueue: delegateQueue + ) + } + } + let newDelegate: URLSessionDelegate? if delegate?.isKind(of: ProxyURLSessionDelegate.self) == true { newDelegate = delegate