Ios 检测应用程序是否在模拟器中运行

Ios 检测应用程序是否在模拟器中运行,ios,xcode,react-native,prop,react-native-ios,Ios,Xcode,React Native,Prop,React Native Ios,在下面的示例中,传递React Native的初始属性不起作用 问题是isSimulator的值被评估为未定义的 Xcode: BOOL isSimulator = NO; #if TARGET_IPHONE_SIMULATOR isSimulator = YES; #endif RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation

在下面的示例中,传递React Native的初始属性不起作用

问题是
isSimulator
的值被评估为
未定义的

Xcode:

  BOOL isSimulator = NO;
#if TARGET_IPHONE_SIMULATOR
  isSimulator = YES;
#endif

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"ReactProject"
                                               initialProperties:@{@"isSimulator": @(isSimulator)}
                                                   launchOptions:launchOptions];
反应:

var isSimulator = this.props.isSimulator;
你可以用

并使用DeviceInfo.getModel()检测模拟器是否为模拟器,如果是模拟器,则返回模拟器

您可以使用以下方法:

const isEmulator=DeviceInfo.isEmulator();//错误

它适用于我使用
Xcode