diff --git a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm index a52d0dd6ca2..0f83d9b9e5b 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -80,8 +80,14 @@ static NSString *getInspectorDeviceId() // A bundle ID uniquely identifies a single app throughout the system. [Source: Apple docs] NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier]; +#if TARGET_OS_IPHONE // An alphanumeric string that uniquely identifies a device to the app's vendor. [Source: Apple docs] NSString *identifierForVendor = [[UIDevice currentDevice] identifierForVendor].UUIDString; +#else + // macOS does not support UIDevice. Use an empty string, with the assumption + // that we are only building to the current system. + NSString *identifierForVendor = @""; +#endif auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance(); diff --git a/packages/react-native/React/DevSupport/RCTInspectorUtils.h b/packages/react-native/React/DevSupport/RCTInspectorUtils.h index b1a977aef82..ae319f4702b 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorUtils.h +++ b/packages/react-native/React/DevSupport/RCTInspectorUtils.h @@ -8,7 +8,7 @@ #import // This is a subset of jsinspector_modern::HostTargetMetadata with ObjC types, -// containing the nonnull members implemented by getHostMetadata. +// containing the members implemented by getHostMetadata. @interface CommonHostMetadata : NSObject @property (nonatomic, strong) NSString *appDisplayName; diff --git a/packages/react-native/React/DevSupport/RCTInspectorUtils.mm b/packages/react-native/React/DevSupport/RCTInspectorUtils.mm index 099bc32b689..01aac9d3433 100644 --- a/packages/react-native/React/DevSupport/RCTInspectorUtils.mm +++ b/packages/react-native/React/DevSupport/RCTInspectorUtils.mm @@ -18,7 +18,16 @@ + (CommonHostMetadata *)getHostMetadata { +#if TARGET_OS_IPHONE UIDevice *device = [UIDevice currentDevice]; + NSString *deviceName = [device name]; +#else + // macOS does not support UIDevice. Use System Configuration. This API + // returns a nullable value, but is non-blocking (compared with + // `[NSHost currentHost]`) and is ideal since deviceName is optional. + NSString *deviceName = (__bridge NSString *)SCDynamicStoreCopyComputerName(nil, nil); +#endif // TARGET_OS_IPHONE + auto version = RCTGetReactNativeVersion(); CommonHostMetadata *metadata = [[CommonHostMetadata alloc] init]; @@ -26,7 +35,7 @@ metadata.appDisplayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleNameKey]; metadata.appIdentifier = [[NSBundle mainBundle] bundleIdentifier]; metadata.platform = RCTPlatformName; - metadata.deviceName = [device name]; + metadata.deviceName = deviceName; metadata.reactNativeVersion = [NSString stringWithFormat:@"%i.%i.%i%@", [version[@"major"] intValue], [version[@"minor"] intValue],