Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swizzleClassNameExcludes doesn't work for RootViewController #4385

Closed
philipphofmann opened this issue Oct 1, 2024 · 0 comments · Fixed by #4407
Closed

swizzleClassNameExcludes doesn't work for RootViewController #4385

philipphofmann opened this issue Oct 1, 2024 · 0 comments · Fixed by #4407
Assignees

Comments

@philipphofmann
Copy link
Member

Description

The logic for swizzling the RootViewController doesn't consider excluding classes in the option swizzleClassNameExcludes.

- (BOOL)swizzleRootViewControllerFromUIApplication:(id<SentryUIApplication>)app
{
if (app.delegate == nil) {
SENTRY_LOG_DEBUG(@"UIViewControllerSwizzling: App delegate is nil. Skipping "
@"swizzleRootViewControllerFromAppDelegate.");
return NO;
}
// Check if delegate responds to window, which it doesn't have to.
if (![app.delegate respondsToSelector:@selector(window)]) {
SENTRY_LOG_DEBUG(@"UIViewControllerSwizzling: UIApplicationDelegate.window is nil. "
@"Skipping swizzleRootViewControllerFromAppDelegate.");
return NO;
}
if (app.delegate.window == nil) {
SENTRY_LOG_DEBUG(@"UIViewControllerSwizzling: UIApplicationDelegate.window is nil. "
@"Skipping swizzleRootViewControllerFromAppDelegate.");
return NO;
}
UIViewController *rootViewController = app.delegate.window.rootViewController;
if (rootViewController == nil) {
SENTRY_LOG_DEBUG(
@"UIViewControllerSwizzling: UIApplicationDelegate.window.rootViewController is nil. "
@"Skipping swizzleRootViewControllerFromAppDelegate.");
return NO;
}
[self swizzleRootViewControllerAndDescendant:rootViewController];
return YES;
}

We should exclude them as we do in the SentrySubClassFinder

BOOL shouldExcludeClassFromSwizzling = NO;
for (NSString *swizzleClassNameExclude in self.swizzleClassNameExcludes) {
if ([className containsString:swizzleClassNameExclude]) {
shouldExcludeClassFromSwizzling = YES;
break;
}
}

@philipphofmann philipphofmann self-assigned this Oct 7, 2024
philipphofmann added a commit that referenced this issue Oct 7, 2024
The SDK didn't exclude the RootViewController from swizzling when
ignored by the option swizzleClassNameExclude. This is fixed now.

Fixes GH-4385
philipphofmann added a commit that referenced this issue Oct 7, 2024
The SDK didn't exclude the RootViewController from swizzling when
ignored by the option swizzleClassNameExclude. This is fixed now.

Fixes GH-4385
philipphofmann added a commit that referenced this issue Oct 8, 2024
The SDK didn't exclude the RootViewController from swizzling when
ignored by the option swizzleClassNameExclude. This is fixed now.

Fixes GH-4385
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant