From 184de0db572f88bd1862aeb189f07a0700b07102 Mon Sep 17 00:00:00 2001 From: Rafal Augustyniak Date: Thu, 29 Aug 2024 23:51:25 -0400 Subject: [PATCH 1/2] attempt at fixing crash with some 3rd parties --- .../extensions/URLSession+Swizzling.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 6e152f9..8d48181 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,29 @@ 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 + // https://github.com/google/gtm-session-fetcher/issues/190#issuecomment-604205556. + 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 From 13c2f15e9a8d8924f5c0aaf2ba1503d3f53209b4 Mon Sep 17 00:00:00 2001 From: Rafal Augustyniak Date: Thu, 29 Aug 2024 23:53:15 -0400 Subject: [PATCH 2/2] better doc --- .../url_session/extensions/URLSession+Swizzling.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 8d48181..6a49334 100644 --- a/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift +++ b/platform/swift/source/integrations/url_session/extensions/URLSession+Swizzling.swift @@ -35,8 +35,10 @@ extension URLSession { if delegate != nil { // Proxying delegates of some 3rd party frameworks leads to crashes. Disable proxying for - // problematic classes - // https://github.com/google/gtm-session-fetcher/issues/190#issuecomment-604205556. + // 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