在模拟器上运行
启动模拟器
¥Starting the simulator
初始化 React Native 项目后,你可以在新创建的项目目录中运行以下命令。
¥Once you have your React Native project initialized, you can run the following command inside the newly created project directory.
- npm
- Yarn
npm run ios
yarn ios
如果一切设置正确,你很快就会看到新应用在 iOS 模拟器中运行。
¥If everything is set up correctly, you should see your new app running in the iOS Simulator shortly.
指定设备
¥Specifying a device
你可以使用 --simulator
标志指定模拟器应运行的设备,后跟字符串形式的设备名称。默认为 "iPhone 14"
。如果你希望在 iPhone SE(第 3 代)上运行应用,请运行以下命令:
¥You can specify the device the simulator should run with the --simulator
flag, followed by the device name as a string. The default is "iPhone 14"
. If you wish to run your app on an iPhone SE (3rd generation), run the following command:
- npm
- Yarn
npm run ios -- --simulator="iPhone SE (3rd generation)"
yarn ios --simulator "iPhone SE (3rd generation)"
设备名称对应于 Xcode 中可用的设备列表。你可以通过从控制台运行 xcrun simctl list devices
来检查可用设备。
¥The device names correspond to the list of devices available in Xcode. You can check your available devices by running xcrun simctl list devices
from the console.
指定设备版本
¥Specifying a version of device
如果你安装了多个 iOS 版本,你还需要指定其适当的版本。例如。要在 iPhone 14 Pro (16.0) 上运行你的应用,请运行以下命令:
¥If you have multiple iOS versions installed, you also need to specify its appropriate version. E.g. To run your app on an iPhone 14 Pro (16.0) run the following command:
- npm
- Yarn
npm run ios -- --simulator="iPhone 14 Pro (16.0)"
yarn ios --simulator "iPhone 14 Pro (16.0)"
指定 UDID
¥Specifying an UDID
你可以指定从 xcrun simctl list devices
命令返回的设备 UDID。例如。要使用 UDID AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA
运行你的应用,请运行以下命令:
¥You can specify the device UDID returned from xcrun simctl list devices
command. E.g. To run your app with UDID AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA
run the following command:
- npm
- Yarn
npm run ios -- --udid="AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
yarn ios --udid "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"