OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在我的设备上而不是在 iPhone 6 模拟器中运行我的 React Native 应用程序? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:27
标题: ios - 如何在我的设备上而不是在 iPhone 6 模拟器中运行我的 React Native 应用程序?

我一直在阅读 React Native 的文档和论坛,并回答了类似的问题,但不知道如何在我的设备上运行我的应用程序。

我已经尝试过这个问题“Run react-native application on iOS device directly from command line?”中提到的内容,以及从 ios 目录中删除 build 文件夹并重新运行脚本。我将运行这个命令 npm run ios --device "Anthony's iPhone",但它会导致这个 Launching iPhone 6 (iOS 11.3)... 我也试过运行npm run ios --simulator "iPhone 5s" 但我再次得到 Launching iPhone 6 (iOS 11.3)...。我不确定从这里去哪里,更多信息可以在下面看到。当然,模拟器总是会启动并正常运行,但我想控制它是在设备上运行还是在哪个模拟器上运行。

Anthonys-MacBook-Pro:fitness-app anthonysette$ npm run ios --device "Anthony’s iPhone"

> [email protected] ios /Users/anthonysette/Documents/fitness-app
> react-native run-ios "Anthony’s iPhone"

Scanning folders for symlinks in /Users/anthonysette/Documents/fitness-app/node_modules (15ms)
Found Xcode workspace FitnessApp.xcworkspace
Launching iPhone 6 (iOS 11.3)...
Building using "xcodebuild -workspace FitnessApp.xcworkspace -configuration Debug -scheme FitnessApp -destination id=28DE4434-4D1A-4B5E-8C16-0AC2C101F8E0 -derivedDataPath build"
User defaults from command line:

编辑:从 package.json 添加信息

我的 package.json 有一个名为 scripts 的部分,其中包含以下内容

  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "rename": "node ./bin/rename.js",
    "start": "react-native start",
    "test": "jest"
  },



Best Answer-推荐答案


您的脚本定义的 npm run ios 将运行 react-native run-ios。 因此,您可以全局安装 react-native cli 并使用

react-native run-ios --device "Anthony’s iPhone"

或将新脚本添加到您的 package.json

"ios-device": "react-native run-ios --device"

然后运行 ​​npm run ios-device "Anthony's iPhone"

关于ios - 如何在我的设备上而不是在 iPhone 6 模拟器中运行我的 React Native 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51790920/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4