diff --git a/Sources/BugsnagPerformance/Private/Instrumentation/ViewLoadInstrumentation.mm b/Sources/BugsnagPerformance/Private/Instrumentation/ViewLoadInstrumentation.mm index f4f35ba0..749df033 100644 --- a/Sources/BugsnagPerformance/Private/Instrumentation/ViewLoadInstrumentation.mm +++ b/Sources/BugsnagPerformance/Private/Instrumentation/ViewLoadInstrumentation.mm @@ -81,10 +81,20 @@ @implementation ViewLoadInstrumentationState initWithNibNameBundle = ObjCSwizzle::replaceInstanceMethodOverride([UIViewController class], selector, ^(id self, NSString *name, NSBundle *bundle) { std::lock_guard guard(vcInitMutex_); auto viewControllerClass = [self class]; - if (*isEnabled && !isClassObserved(viewControllerClass)) { - Trace(@"%@ -[%s %s]", self, class_getName(viewControllerClass), sel_getName(selector)); - instrument(viewControllerClass); - (*classToIsObserved)[viewControllerClass] = true; + auto appPath = NSBundle.mainBundle.bundlePath.UTF8String; + auto viewControllerBundlePath = [NSBundle bundleForClass: viewControllerClass].bundlePath.UTF8String; + if (strstr(viewControllerBundlePath, appPath) +#if TARGET_OS_SIMULATOR + // and those loaded from BUILT_PRODUCTS_DIR, because Xcode + // doesn't embed them when building for the Simulator. + || strstr(viewControllerBundlePath, "/DerivedData/") +#endif + ) { + if (*isEnabled && !isClassObserved(viewControllerClass)) { + Trace(@"%@ -[%s %s]", self, class_getName(viewControllerClass), sel_getName(selector)); + instrument(viewControllerClass); + (*classToIsObserved)[viewControllerClass] = true; + } } reinterpret_cast(initWithNibNameBundle)(self, selector, name, bundle); });