gtm-session-fetcher: Invalid cast in GTMSessionFetcherService
Hello
This issue was described in several tickets but solution is still not there.
There are several third-party libraries that swizzle URLSession
’s delegate
with their own proxy objects. For example TrustKit and SplunkMint do that. However GTMSessionFetcherService
completely ignores this fact and hard-casts these proxy objects to its own class - GTMSessionFetcherSessionDelegateDispatcher
:
BOOL hasDispatcher = (fetcherDelegate != nil &&
![fetcherDelegate isKindOfClass:[GTMSessionFetcher class]]);
if (hasDispatcher) {
GTMSESSION_ASSERT_DEBUG([fetcherDelegate isKindOfClass:[GTMSessionFetcherSessionDelegateDispatcher class]],
@"Fetcher delegate class: %@", [fetcherDelegate class]);
return (GTMSessionFetcherSessionDelegateDispatcher *)fetcherDelegate;
}
Obviously later we get crashes in different places due to “unrecognized selector sent to instance” exceptions.
The “dumb” solution is to check the class of object before casting it:
if ([fetcherDelegate isKindOfClass:[GTMSessionFetcherSessionDelegateDispatcher class]]) {
return (GTMSessionFetcherSessionDelegateDispatcher *)fetcherDelegate;
}
else {
return nil;
}
But having almost zero knowledge of how GTMSessionFetcher works, it’s hard for me to understand if this code breaks something else. Any advice from the team?
We consume this library indirectly via FirebaseAuth.
Thanks, Vlad
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 23 (3 by maintainers)
I hope this will get fixed sometime in the future. For now this is a workaround we applied:
Just call
GTMSessionFetcherService.swizzleDelegateDispatcherForFetcher()
before using Firebase. Hope this will help others.Thank you so much @oailloud. This solved my issue. I had to import
#import "GTMSessionFetcherService.h"
and also#import "<projectname>-Swift.h"
as per this : https://stackoverflow.com/questions/58233526/no-known-class-method-for-selector-name/58233691#58233691