【问题标题】:How to specify specific simulator for iOS?如何为 iOS 指定特定的模拟器?
【发布时间】:2019-04-10 12:37:54
【问题描述】:

我正在使用 Visual Studio 代码扩展“React Native Tools” 用于在模拟器/设备上运行和构建我的 react 本机应用程序。

有没有办法为 ex 指定模拟器版本。 “iPhone X Max”?

目前,当我为“Debug iOS”启动构建配置时,模拟器“iPhone X”会自动启动。

这是我的 launch.json:

{
"version": "0.2.0",
"configurations": [

    {
        "name": "Debug iOS",
        "program": "${workspaceRoot}/.vscode/launchReactNative.js",
        "type": "reactnative",
        "request": "launch",
        "platform": "ios",
        "sourceMaps": true,
        "target": "simulator",
        "outDir": "${workspaceRoot}/.vscode/.react"
    }, 
    {
        "name": "Debug iOS device",
        "program": "${workspaceRoot}/.vscode/launchReactNative.js",
        "type": "reactnative",
        "request": "launch",
        "platform": "ios",
        "sourceMaps": true,
        "target": "device",
        "outDir": "${workspaceRoot}/.vscode/.react"
    }, 
    {
        "name": "Debug Android",
        "program": "${workspaceRoot}/.vscode/launchReactNative.js",
        "type": "reactnative",
        "request": "launch",
        "platform": "android",
        "sourceMaps": true,
        "target": "simulator",
        "outDir": "${workspaceRoot}/.vscode/.react"
    }

]}

【问题讨论】:

    标签: ios macos react-native vscode-settings


    【解决方案1】:

    您可以在目标键本身中指定模拟器:

    {
        "name": "Debug iOS",
        "program": "${workspaceRoot}/.vscode/launchReactNative.js",
        "type": "reactnative",
        "request": "launch",
        "platform": "ios",
        "sourceMaps": true,
        "target": "iPhone Xs Max",
        "outDir": "${workspaceRoot}/.vscode/.react"
    }
    

    参考:

    1. VSCode React Native - GitHub Repo
    2. Setting up debug environment - Guide

    【讨论】:

    • 谢谢,我刚刚发布了我找到的解决方案,您可以在下面查看。您的配置也将起作用,但您的 iPhone 模拟器名称有误。它应该是“iPhone Xs Max”而不是“iPhone XS Max”。
    • 我将您的提案标记为答案,因为它是最干净的解决方案。 :)
    【解决方案2】:

    我找到了解决办法。

    刚刚添加了这个

    "runArguments": ["--simulator", "iPhone Xs Max"]

    到我在 launch.json 中的启动配置

    这是现在的样子:

    {
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "Debug iOS",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "ios",
            "sourceMaps": true,
            "target": "simulator",
            "runArguments": ["--simulator", "iPhone Xs Max"],
            "outDir": "${workspaceRoot}/.vscode/.react"
        }, 
        {
            "name": "Debug iOS device",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "ios",
            "sourceMaps": true,
            "target": "device",
            "outDir": "${workspaceRoot}/.vscode/.react"
        }, 
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "target": "simulator",
            "outDir": "${workspaceRoot}/.vscode/.react"
        }
    
    ]}
    

    【讨论】:

      【解决方案3】:

      --simulator "deviceName" 添加到react-native run-ios 将让您选择模拟器。

      适用于 iPhone XS Max

      react-native run-ios --simulator "iPhone XS Max"
      

      【讨论】:

      • 我没有从终端运行我的应用程序。我在问如何在 launch.json 配置中指定模拟器版本,因为我使用的是 React Native Tools。
      • 我不知道你在说什么,但是,无论如何,你为什么不打开一个终端并运行那个命令呢?无论如何,在 VSCode 中,您可以使用快捷键 CTRL+^ 打开终端,然后运行该命令。
      • 这不能回答我的问题。无论如何,我找到了解决方案,稍后会发布。
      • 好的,我明白了!很高兴您找到了解决方案
      • 你可以在下面找到它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 2019-02-18
      • 2014-12-27
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多