【问题标题】:Detect if app React app is running in simulator检测应用程序 React 应用程序是否在模拟器中运行
【发布时间】:2016-10-17 15:54:27
【问题描述】:

按照示例传递 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;

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      Xcode 对我有用

      【讨论】:

        猜你喜欢
        • 2012-06-21
        • 1970-01-01
        • 2019-05-31
        • 2011-06-12
        • 2011-08-12
        • 2015-11-05
        • 1970-01-01
        • 2015-10-14
        相关资源
        最近更新 更多