如何为iOS指定特定的模拟器?

时间:2019-04-10 12:37:55

标签: ios macos react-native vscode-settings

我正在使用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"
    }

]}

3 个答案:

答案 0 :(得分:3)

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

{
    "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

答案 1 :(得分:3)

我找到了解决方法。

只需添加此

  

“ 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"
    }

]}

答案 2 :(得分:1)

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

适用于iPhone XS Max

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