xcode 如何从命令行安装 iOS 模拟器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34493934/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:22:03  来源:igfitidea点击:

How to install iOS simulators from command line

iosxcodecontinuous-integrationios-simulator

提问by Quanlong

It's a common case to run tests against different versions of iOS simulators/SDKs on CI. However, only the latest iOS simulator is installed by Xcode on default.

在 CI 上针对不同版本的 iOS 模拟器/SDK 运行测试是一种常见情况。但是,Xcode 默认只安装最新的 iOS 模拟器。

So I need install other missing iOS simulators from command line in CI environment. But I cannot find a way to install those simulators from command line.

所以我需要在 CI 环境中从命令行安装其他缺少的 iOS 模拟器。但是我找不到从命令行安装这些模拟器的方法。

回答by Quanlong

It can be done with xcode-install, with the following commands

可以使用xcode-install 完成,使用以下命令

gem install xcode-install
xcversion simulators --install='iOS 9.3'

回答by iPrabu

FYI

供参考

All simulators are packed with Xcode app. Instead of installing simulators you can just install the specific Xcode versions. Xcode7.0 has iOS9 Simulators Xcode6.4 has iOS8.x Simulators

所有模拟器都装有 Xcode 应用程序。您可以安装特定的 Xcode 版本,而不是安装模拟器。Xcode7.0 有 iOS9 模拟器 Xcode6.4 有 iOS8.x 模拟器

In your CI testing if you want to test you app for a specific simulator just select xcode version before you do the xcodebuild command

在您的 CI 测试中,如果您想针对特定模拟器测试您的应用程序,只需在执行 xcodebuild 命令之前选择 xcode 版本

xcode-select -switch <path to your xcode app>

This will set your default xcode to run the xcodebuild Then run the xcodebuild with your respective simulator.

这将设置您的默认 xcode 以运行 xcodebuild 然后使用您各自的模拟器运行 xcodebuild。

xcodebuild -configuration ${BUILD_TYPE} -target ${TARGET_NAME} -arch ${CPU_ARCHITECTURE} -sdk ${SIMULATOR_OR_IOS_SDK} 

In the place of SIMULATOR_OR_IOS_SDKgive your simulator value.

代替SIMULATOR_OR_IOS_SDK给你的模拟器值。

You can find the simulator value by running

您可以通过运行找到模拟器值

xcodebuild -showsdks

This will show like

这将显示为

OS X SDKs:
    OS X 10.11                      -sdk macosx10.11

iOS SDKs:
    iOS 9.1                         -sdk iphoneos9.1

iOS Simulator SDKs:
    Simulator - iOS 9.1             -sdk iphonesimulator9.1

tvOS SDKs:
    tvOS 9.0                        -sdk appletvos9.0

tvOS Simulator SDKs:
    Simulator - tvOS 9.0            -sdk appletvsimulator9.0

watchOS SDKs:
    watchOS 2.0                     -sdk watchos2.0

watchOS Simulator SDKs:
    Simulator - watchOS 2.0         -sdk watchsimulator2.0

This way you can build your project on any specific device/simulator/os.

通过这种方式,您可以在任何特定设备/模拟器/操作系统上构建您的项目。

Hope this helps :)

希望这可以帮助 :)

回答by RY Zheng

xcrun simctl create <name> <device type> <runtime>

For example:

例如:

xcrun simctl create "ry" "iPhone 11 Pro Max" iOS13.3  

xcrun simctlis command utils to control iOS simulator, just like adbfor Android. You can also run xcrun simctl help, there are a bundle of useful subcommands. When successful, most of these commands exit with 0; when failed, most exit with a non-zero number.

xcrun simctl是控制iOS模拟器的命令工具,就像adbAndroid一样。您也可以运行xcrun simctl help,有一堆有用的子命令。成功时,这些命令中的大多数以 0 退出;失败时,大多数以非零数字退出。