diff --git a/Sources/Sentry/SentryBreadcrumbTracker.m b/Sources/Sentry/SentryBreadcrumbTracker.m index f3545d5dcd5..072e6305b13 100644 --- a/Sources/Sentry/SentryBreadcrumbTracker.m +++ b/Sources/Sentry/SentryBreadcrumbTracker.m @@ -41,6 +41,7 @@ - (instancetype)initWithSwizzleWrapper:(SentrySwizzleWrapper *)swizzleWrapper - (void)startWithDelegate:(id)delegate { + NSLog(@"Starting %@ with delegate: %@", self, delegate); _delegate = delegate; [self addEnabledCrumb]; [self trackApplicationUIKitNotifications]; @@ -201,6 +202,33 @@ - (void)swizzleViewDidAppear static const void *swizzleViewDidAppearKey = &swizzleViewDidAppearKey; SEL selector = NSSelectorFromString(@"viewDidAppear:"); __weak id delegate = self.delegate; + SentryBreadcrumbTracker *__weak tracker = self; + + // [SentrySwizzle + // swizzleInstanceMethod:selector + // inClass:UIViewController.class + // newImpFactory:^id(SentrySwizzleInfo *swizzleInfo) { + // return ^(__unsafe_unretained id self, + // BOOL animated) { + // SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] + // initWithLevel:kSentryLevelInfo + // category:@"ui.lifecycle"]; + // crumb.type = @"navigation"; + // crumb.data = [SentryBreadcrumbTracker + // fetchInfoAboutViewController:self]; + // + // NSLog(@"tracker: %@; __weak id: %@; crumb: + // %@", tracker, delegate, crumb); + // + // [delegate addBreadcrumb:crumb]; + // + // ((void (*)(__unsafe_unretained id, SEL))[swizzleInfo + // getOriginalImplementation])(self, selector); + // }; + // } + // mode:SentrySwizzleModeOncePerClassAndSuperclasses + // key:swizzleViewDidAppearKey]; + SentrySwizzleInstanceMethod(UIViewController.class, selector, SentrySWReturnType(void), SentrySWArguments(BOOL animated), SentrySWReplacement({ SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo @@ -208,7 +236,8 @@ - (void)swizzleViewDidAppear crumb.type = @"navigation"; crumb.data = [SentryBreadcrumbTracker fetchInfoAboutViewController:self]; - NSLog(@"__weak id: %@; crumb: %@", delegate, crumb); + NSLog(@"tracker: %@; __weak id: %@; crumb: %@", tracker, + delegate, crumb); [delegate addBreadcrumb:crumb]; diff --git a/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift b/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift index e302e30cbb1..709179e7c6c 100644 --- a/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift @@ -43,6 +43,8 @@ class SentryBreadcrumbTrackerTests: XCTestCase { let viewController = UIViewController() _ = UINavigationController(rootViewController: viewController) viewController.title = "test title" + print("delegate: \(String(describing: delegate))") + print("tracker: \(sut); SentryBreadcrumbTracker.delegate: \(String(describing: Dynamic(sut).delegate.asObject))") viewController.viewDidAppear(false) let crumbs = delegate.addCrumbInvocations.invocations