【发布时间】:2019-01-18 07:55:00
【问题描述】:
我一直在阅读 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"
> FitnessApp@0.1.0 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"
},
【问题讨论】:
-
你也可以试试这个
react-native run-ios --device吗? -
@PritishVaidya 刚试过,但对我来说
npm run ios运行react-native run-ios。该命令的结果是Anthonys-MacBook-Pro:fitness-app anthonysette$ react-native run-ios --device bash: react-native: command not found -
检查我的编辑,在我的项目中添加了一些关于 package.json 文件的信息。
-
您可以全局安装
react-native cli或将脚本添加到您的 package.json 为"ios-device": "react-native run-ios --device"并运行npm run ios-device -
@PritishVaidya 成功了!!!我现在得到这个
Could not find device with the name: "true". Choose one of the following: Anthony’s iPhone Udid: __UID__ Anthony’s MacBook Pro Udid: __UID__ Anthonys-MacBook-Pro:fitness-app anthonysette$,我该如何选择?另外,如果您想将其作为答案提交,我很乐意将其标记为已回答以供其他人查看!
标签: ios react-native react-native-ios react-native-firebase