1

按照示例传递 React Native 的初始属性不起作用。

问题是 的值isSimulator被评估为undefined

代码:

  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;
4

2 回答 2

1

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

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

于 2016-12-16T19:20:01.363 回答
0

你可以使用这个方法:Github Link

const isEmulator = DeviceInfo.isEmulator(); // false

它对我有用Xcode

于 2019-05-24T09:43:33.147 回答