直接从命令行在 iOS 设备上运行 react-native 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38495793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run react-native application on iOS device directly from command line?
提问by Aakash Sigdel
Is it possible to run react-native application on an iOS device directly from the command line like we do on simulator with react-native run ios --simulator "iPhone 5s"
?
是否可以像我们在模拟器上那样直接从命令行在 iOS 设备上运行 react-native 应用程序react-native run ios --simulator "iPhone 5s"
?
回答by Kamil Sarna
The following worked for me (tested on react native 0.38
and 0.40
):
以下对我有用(在 react native0.38
和上测试0.40
):
npm install -g ios-deploy
# Run on a connected device, e.g. Max's iPhone:
react-native run-ios --device "Max's iPhone"
If you try to run run-ios
, you will see that the script recommends to do npm install -g ios-deploy
when it reach install step after building.
如果您尝试运行run-ios
,您将看到脚本npm install -g ios-deploy
在构建后到达安装步骤时建议执行。
While the documentation on the various commands that react-native offers is a little sketchy, it is worth going to react-native/local-cli. There, you can see all the commands available and the code that they run - you can thus work out what switches are available for undocumented commands.
虽然 react-native 提供的各种命令的文档有点粗略,但值得去react-native/local-cli。在那里,您可以看到所有可用的命令以及它们运行的代码——因此您可以确定哪些开关可用于未记录的命令。
回答by jasonleonhard
First install the required library globally on your computer:
首先在您的计算机上全局安装所需的库:
npm install -g ios-deploy
Go to your settings on your iPhone to find the name of the device.
转到 iPhone 上的设置以查找设备名称。
Then provide that below like:
然后提供如下:
react-native run-ios --device "______\'s iPhone"
Sometimes this will fail and output a message like this:
有时这会失败并输出如下消息:
Found Xcode project ________.xcodeproj
Could not find device with the name: "_______'s iPhone".
Choose one of the following:
______'s iPhone Udid: _________
That udid is used like this:
那个 udid 是这样使用的:
react-native run-ios --device --udid 0412e2c230a14e23451699
Optionally you may use:
您可以选择使用:
react-native run-ios --device --udid 0412e2c230a14e23451699 -- configuration Release
回答by kuldip bhalodiya
Run this command in project root directory.
在项目根目录下运行此命令。
1>. List of iPhone devicesfor found the connected Real Devices and Simulator. same as like adb devices command for android.
1>. 找到连接的真实设备和模拟器的 iPhone 设备列表。与 android 的 adb devices 命令一样。
xcrun instruments -s devices
2>. Select device using this command which you want to run your app
2>。使用此命令选择要运行应用程序的设备
Using Device Name
使用设备名称
react-native run-ios --device "Kool's iPhone"
Using UDID
使用 UDID
react-native run-ios --device --udid 0412e2c2******51699
wait and watch to run your app in specific devices - K00L ;)
等待并观察在特定设备上运行您的应用程序 - K00L ;)
回答by Cedriga
If you get this error [email protected] preinstall: ./src/scripts/check_reqs.js && xcodebuild ...
using npm install -g ios-deploy
如果您[email protected] preinstall: ./src/scripts/check_reqs.js && xcodebuild ...
使用npm install -g ios-deploy
Try this. It works for me:
尝试这个。这个对我有用:
sudo npm uninstall -g ios-deploy
brew install ios-deploy
sudo npm uninstall -g ios-deploy
brew install ios-deploy
回答by Damitha Raveendra
Just wanted to add something to Kamil's answer
只是想在 Kamil 的回答中添加一些内容
After following the steps, I still got an error,
按照步骤操作后还是报错
error Could not find device with the name: "....'s Xr"
错误找不到名称为“....'s Xr”的设备
After removing special characters from the device name (Go to Settings -> General -> About -> Name)
从设备名称中删除特殊字符后(转到Settings -> General -> About -> Name)
Eg: '
例如:'
It Worked !
有效 !
Hope this will help someone who faced similar issue.
希望这会帮助遇到类似问题的人。
Tested with- react-native-cli: 2.0.1| react-native: 0.59.8| VSCode 1.32| Xcode 10.2.1| iOS 12.3
测试- react-native-cli: 2.0.1| 反应原生:0.59.8| VSCode 1.32| Xcode 10.2.1| iOS 12.3