diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index be1b40fe146c85..42b7590c7f878c 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -20,6 +20,7 @@ #import #import #import "RCTDevLoadingViewProtocol.h" +#import "RCTInspectorUtils.h" #import "RCTJSThread.h" #import "RCTLog.h" #import "RCTModuleData.h" @@ -199,8 +200,14 @@ void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled) facebook::react::jsinspector_modern::HostTargetMetadata getMetadata() override { + auto metadata = [RCTInspectorUtils getHostMetadata]; + return { + .appIdentifier = metadata.appIdentifier, + .deviceName = metadata.deviceName, .integrationName = "iOS Bridge (RCTBridge)", + .platform = metadata.platform, + .reactNativeVersion = metadata.reactNativeVersion, }; } diff --git a/packages/react-native/React/DevSupport/RCTInspectorUtils.h b/packages/react-native/React/DevSupport/RCTInspectorUtils.h new file mode 100644 index 00000000000000..d4b14415876a53 --- /dev/null +++ b/packages/react-native/React/DevSupport/RCTInspectorUtils.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import + +struct CommonHostMetadata { + std::string appIdentifier; + std::string deviceName; + std::string platform; + std::string reactNativeVersion; +}; + +@interface RCTInspectorUtils : NSObject + ++ (CommonHostMetadata)getHostMetadata; + +@end diff --git a/packages/react-native/React/DevSupport/RCTInspectorUtils.mm b/packages/react-native/React/DevSupport/RCTInspectorUtils.mm new file mode 100644 index 00000000000000..fd4821d19ea461 --- /dev/null +++ b/packages/react-native/React/DevSupport/RCTInspectorUtils.mm @@ -0,0 +1,42 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTInspectorUtils.h" + +#import +#import +#import + +@implementation RCTInspectorUtils + ++ (CommonHostMetadata)getHostMetadata +{ + UIDevice *device = [UIDevice currentDevice]; + + NSString *appIdentifier = [[NSBundle mainBundle] bundleIdentifier]; + NSString *platform = RCTPlatformName; + NSString *deviceName = [device name]; + + auto version = RCTGetReactNativeVersion(); + NSString *reactNativeVersion = + [NSString stringWithFormat:@"%i.%i.%i%@", + [version[@"minor"] intValue], + [version[@"major"] intValue], + [version[@"patch"] intValue], + [version[@"prerelease"] isKindOfClass:[NSNull class]] + ? @"" + : [@"-" stringByAppendingString:[version[@"prerelease"] stringValue]]]; + + return { + .appIdentifier = [appIdentifier UTF8String], + .platform = [platform UTF8String], + .deviceName = [deviceName UTF8String], + .reactNativeVersion = [reactNativeVersion UTF8String], + }; +} + +@end diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp index 00810280c05eb5..7a74ccf36b1335 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp @@ -223,7 +223,11 @@ bool HostTargetController::decrementPauseOverlayCounter() { folly::dynamic hostMetadataToDynamic(const HostTargetMetadata& metadata) { folly::dynamic result = folly::dynamic::object; + result["appIdentifier"] = metadata.appIdentifier.value_or(nullptr); + result["deviceName"] = metadata.deviceName.value_or(nullptr); result["integrationName"] = metadata.integrationName.value_or(nullptr); + result["platform"] = metadata.platform.value_or(nullptr); + result["reactNativeVersion"] = metadata.reactNativeVersion.value_or(nullptr); return result; } diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.h b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.h index 9fb5ab26f3691d..6a56ea2407906e 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.h @@ -37,7 +37,11 @@ class HostCommandSender; class HostTarget; struct HostTargetMetadata { + std::optional appIdentifier; + std::optional deviceName; std::optional integrationName; + std::optional platform; + std::optional reactNativeVersion; }; /** @@ -90,7 +94,8 @@ class HostTargetDelegate { virtual ~HostTargetDelegate(); /** - * Returns a metadata object describing the host. + * Returns a metadata object describing the host. This is called on an + * initial response to @cdp ReactNativeApplication.enable. */ virtual HostTargetMetadata getMetadata() = 0; diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm index 8e0b105f2c54a7..8a93548b094ed1 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm @@ -13,6 +13,7 @@ #import #import #import +#import #import #import #import @@ -42,8 +43,14 @@ @interface RCTHost () jsinspector_modern::HostTargetMetadata getMetadata() override { + auto metadata = [RCTInspectorUtils getHostMetadata]; + return { + .appIdentifier = metadata.appIdentifier, + .deviceName = metadata.deviceName, .integrationName = "iOS Bridgeless (RCTHost)", + .platform = metadata.platform, + .reactNativeVersion = metadata.reactNativeVersion, }; }