Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native in VS Code: add configuration for iOS Device to launch.json

I have a React Native project open in Visual Studio code, and Im trying to run the project on a physical connected iOS device. I successfully ran the app on the device directly from Xcode, but from Visual Studio Code I'm having issues. I believe I need to add a configuration for the device into launch.json. I have tried different entries in there but non seem to work. What is the proper way to add a configuration for a connected iOS device?

like image 430
pnizzle Avatar asked Jul 03 '17 04:07

pnizzle


People also ask

How to run react native app on Android device?

Running your app on Android devices 1 Enable Debugging over USB Most Android devices can only install and run apps downloaded from Google Play, by default. ... 2 Plug in your device via USB Let's now set up an Android device to run our React Native projects. ... 3 Run your app

Can I use React Native with Visual Studio?

Visual Studio. ReactNative is a great way to build native, cross platform app for iOS and Android using JavaScript. We recently announced the launch of a Visual Studio Code Extension that enables you to build, debug and preview Apache Cordova apps. And today we’re pleased to announce the availability a similar extension for ReactNative!

What is the difference between Cordova and React Native?

ReactNative apps are also written with JavaScript – or, more specifically, they are written with the React/JSX framework. But, rather than run in a Webview like Cordova, code runs in a JavaScript engine that’s bundled with the app. ReactNative then invokes native UI components (e.g. UITabBar on iOS and Drawer on Android) via JavaScript.

How long does it take to install React Native on Mac?

It’s under 50MB, completely free, and runs on Mac OS X, Linux, and Windows. On a decent network connection you’ll have it installed in under 2 minutes! Then visit the Visual Studio Code Marketplace to get the ReactNative extension. You can also install it directly from within the editor.


2 Answers

If you need to target a specific device, this is how it´s done:

{
  "name": "iOS Device",
  "program": "${workspaceRoot}/.vscode/launchReactNative.js",
  "type": "reactnative",
  "request": "launch",
  "platform": "ios",
  "sourceMaps": true,
  "target": "device",
  "outDir": "${workspaceRoot}/.vscode/.react",
  "runArguments": [
    "--device",
    "DEVICE NAME"
  ],
}

So you need to set "target": "device" to tell the debugger to run on a device, and then you set the device name through "runArguments".

like image 199
Johannes Avatar answered Sep 23 '22 10:09

Johannes


Try with react-native run-ios --device "your device name"

Device name you can find in xcode

You can add this in package.json also

{
    start:ios: "node node_modules/react-native/local-cli/cli.js run-ios --device \"your device name\""
}

You may need to install ios-deploy

npm install -g ios-deploy

For vscode launch.json you can add these configuration node node_modules/react-native/local-cli/cli.js run-ios --device \"your device name\" in launch.json too

launch.json

{
        "type": "node",
        "request": "launch",
        "name": "Run app",
        "program": "${workspaceRoot}/node_modules/react-native/local-cli/cli.js",
        "cwd": "${workspaceRoot}",
        "runtimeArgs": [
            "run-ios",
            "--device",
            "\"your device name\""
        ],
    }
like image 37
Kishan Mundha Avatar answered Sep 24 '22 10:09

Kishan Mundha