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

时间:2016-10-17 15:54:27

标签: ios xcode react-native prop react-native-ios

在遵循示例时,传递React Native的初始属性并不起作用。

问题在于isSimulator的值被评估为undefined

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;

2 个答案:

答案 0 :(得分:1)

您可以使用https://github.com/rebeccahughes/react-native-device-info

并通过使用DeviceInfo.getModel()检测模拟器是否会返回模拟器(如果它是模拟器)

答案 1 :(得分:0)

您可以使用以下方法:Github Link

--master

它与const isEmulator = DeviceInfo.isEmulator(); // false一起对我有用

相关问题