有没有办法使用 xcode/iphone sim 模拟多个 iphone?

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

Is there a way to simulate multiple iphones using xcode/iphone sim?

iphonexcodesimulator

提问by Abel

I'm planning out a game that requires multiple users and I was wondering if there's a way to fire up multiple instances of the iPhone Simulator. I didn't see anything in menus or in Google search results, but I just wanted to make sure I wasn't missing anything.

我正在计划一个需要多个用户的游戏,我想知道是否有办法启动 iPhone 模拟器的多个实例。我没有在菜单或 Google 搜索结果中看到任何东西,但我只是想确保我没有遗漏任何东西。

采纳答案by Ramin

As near as I can tell, not only can you not have multiple instances of the simulator running, but when time comes for actual device testing you can't have multiple instances of the debugger running either.

据我所知,您不仅不能运行多个模拟器实例,而且当需要进行实际设备测试时,您也不能运行多个调试器实例。

This means to do multi-device apps, you'll need to have a single Mac assigned to a single iPhone/touch device (or simulator instance) each running your app.

这意味着要执行多设备应用程序,您需要将一台 Mac 分配给每个运行您的应用程序的单个 iPhone/触摸设备(或模拟器实例)。

I've started looking into whether VMWare or Parallels can somehow be brought into this, but there's not much that can be done without hacking the OS.

我已经开始研究是否可以以某种方式将 VMWare 或 Parallels 带入其中,但如果不入侵操作系统,就无能为力了。

I suggest filing a feature request with http://bugreporter.apple.com.

我建议向http://bugreporter.apple.com提交功能请求。

回答by lvsti

It is possible but only with multiple users.

这是可能的,但仅限于多个用户。

Read this: http://www.coderebel.com/2010/08/31/iphone_simulator

阅读:http: //www.coderebel.com/2010/08/31/iphone_simulator

Assuming you have two projects (P1,P2) which you want to debug simultaneously, do as follows.

假设您有两个要同时调试的项目(P1、P2),请执行以下操作。

Steps to set up:

设置步骤:

  1. Create a new user (U2) on your Mac
  2. Give it R/W access to P2, especially to its build folder.
  3. Download the launcher app from the site above and copy it to Applications.
  1. 在 Mac 上创建新用户 (U2)
  2. 授予它对 P2 的 R/W 访问权限,尤其是对其构建文件夹的访问权限。
  3. 从上面的站点下载启动器应用程序并将其复制到应用程序。

Steps to debug:

调试步骤:

  1. Close Xcode and the simulator if running
  2. Launch the iPhone Launcher.app with U1.
  3. Start Xcode with U1, load P1, start debugging.
  4. Launch the iPhone Launcher.app with U2.
  5. Start Xcode with U2, load P2, start debugging.
  1. 如果运行,请关闭 Xcode 和模拟器
  2. 使用 U1 启动 iPhone Launcher.app。
  3. 用 U1 启动 Xcode,加载 P1,开始调试。
  4. 使用 U2 启动 iPhone Launcher.app。
  5. 用 U2 启动 Xcode,加载 P2,开始调试。

Unfortunately it's a P.I.T.A. having to change users every now and then but so far I haven't found any better solution. Hope this helps.

不幸的是,PITA 不得不时不时地更改用户,但到目前为止我还没有找到任何更好的解决方案。希望这可以帮助。

回答by FlowUI. SimpleUITesting.com

There is a way to do this easily without using multiple users. Keep in mind you will not be connected to the debugger though. Keep in mind the explanation below is for XCode 6+. You can skip this explanation and just scroll down to the wrapping-it-up section below.

有一种方法可以在不使用多个用户的情况下轻松完成此操作。请记住,您不会连接到调试器。请记住,下面的解释是针对XCode 6+ 的。您可以跳过此说明,只需向下滚动到下面的 wrapping-it-up 部分。

From an answer herewe can see that you can launch any simulator from command line:

这里的答案中我们可以看到您可以从命令行启动任何模拟器:

open -a "iOS Simulator" --args -CurrentDeviceUDID

open -a "iOS Simulator" --args -CurrentDeviceUDID

You can find the deviceID (as well as all your simulators) by running the xcrun simctl listcommand on console. It will generate a list like this. The device ID is the code in braces:

您可以通过xcrun simctl list在控制台上运行命令来找到设备 ID(以及所有模拟器)。它会生成一个这样的列表。设备 ID 是大括号中的代码:

== Runtimes ==
iOS 8.3 (8.3 - 12F69) (com.apple.CoreSimulator.SimRuntime.iOS-8-3)
== Devices ==
-- iOS 8.3 --
    iPhone 4s (99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8) (Shutdown)
    iPhone 5 (K262AF11-ADD2-4FDA-ACBA-8C80DD9D4AA1) (Shutdown)
    iPhone 5s (337KDC51-0A4B-47DB-8966-83562FD92C93) (Shutdown)
    iPhone 6 Plus (9GK714E2-F713-4F98-A96E-C72ACD6571A8) (Shutdown)
-- iOS 8.2 --
    etc continued....

Therefore to run the simulator using above as example, run this command on console:

因此,要使用上面的示例运行模拟器,请在控制台上运行以下命令:

open -n /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/ --args -CurrentDeviceUDID '99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8'

We use the -nflag instead because the -aflag specifies the application to use for opening the file, while the -nflag opens a new instance of the application(s) even if one is already running. Use the man opencommand to know all this stuff.

我们使用该-n标志是因为该-a标志指定了用于打开文件的应用程序,而该-n标志会打开应用程序的一个新实例,即使一个应用程序已经在运行。使用man open命令来了解所有这些东西。

Also make sure you have the correct path for your simulator.

还要确保您的模拟器路径正确。

One more thing to note, if you run the simulator like this, chances are that you have limited simulators. And since its limited, you might want to launch it without interrupting one that's already on the screen. We can solve this from this answer herewhere he shows you how to create a new simulator and delete one.

还有一点要注意,如果你像这样运行模拟器,很可能你的模拟器是有限的。而且由于它是有限的,您可能希望在不中断屏幕上已经存在的情况下启动它。我们可以从这个回答解决了这个位置,在那里他展示了如何create a new simulator and delete one.

So wrapping it all up, here's what you do to launch them.

总而言之,这就是启动它们的方法。

A) First Create a simulator before launching it.

A) 在启动之前首先创建一个模拟器。

Usage: simctl create "name" "device type id" "runtime id"

用法:simctl create "name" "device type id" "runtime id"

xcrun simctl create "mynewsimulator" "iPhone 6" "com.apple.CoreSimulator.SimRuntime.iOS-8-3"

You will find the runtime id from the command xcrun simctl listcommand I ran above. After running the above command, the deviceID will be printed on the console screen. Take note of it as you will need as the last argument to launch the simulator shown below. Let's assume this ID was 99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8

您将从xcrun simctl list我上面运行的命令命令中找到运行时 ID 。运行上述命令后,设备ID将打印在控制台屏幕上。记下它,因为您将需要作为启动下面显示的模拟器的最后一个参数。让我们假设这个 ID 是99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8

B) launch it

B) 启动它

open -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ --args -CurrentDeviceUDID '99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8'

C) delete it once you're finished with your simulator

C)完成模拟器后删除它

xcrun simctl delete 99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8

All this can be placed in a single .sh file for easy running. Please note to put waitor sleepcommands after each command if you decide to put all this into a sh file.

所有这些都可以放在一个 .sh 文件中,以便于运行。如果您决定将所有这些都放入一个 sh 文件中,请注意在每个命令之后放置waitsleep命令。

[EDIT 2017]I see that XCode 9 will now support multiple simulators. Awaiting to see how it will all work.

[编辑 2017]我看到 XCode 9 现在将支持多个模拟器。等待看看这一切将如何运作。

回答by Mike

Another option (albeit probably overkill) if you have a Mac OS X server license is to virtualize an instance of Mac OS X Server, and run a second simulator in the VM.

如果您拥有 Mac OS X 服务器许可证,另一种选择(尽管可能有点矫枉过正)是虚拟化 Mac OS X Server 的一个实例,然后在 VM 中运行第二个模拟器。

回答by RexOnRoids

Hmm...I don't think you are missing anything here. As far as I know there is no technology within the SDK that is able to emulate multiple devices -- though that would be a useful feature to have. I think your only options would be to get a second iPhone OS device, or get a friend who also has an iPhone OS device to let you use it for testing.

嗯……我不认为你在这里遗漏了任何东西。据我所知,SDK 中没有能够模拟多个设备的技术——尽管这将是一个有用的功能。我认为您唯一的选择是获得第二个 iPhone OS 设备,或者找一个也有 iPhone OS 设备的朋友让您使用它进行测试。

回答by Ravikant Nagar

Follow these steps to test your app.

请按照以下步骤测试您的应用。

You have to do one thing for whole process first : Go to Project - > Edit Project Settings -> tick on option - Build independent targets in parallel.

您必须首先为整个过程做一件事:转到项目 - > 编辑项目设置 - > 勾选选项 - 并行构建独立目标。

  1. Debug code that will create your app in simulator For Example your App name is - Instance
  2. Close Simulator
  3. Go to Project->New Target -> Instance2 Add "Bundle display name : Instance2" in Instance2.info.plist file Set Executable Name : Instance2 Select Instance2 Target -> Go to Project -> Set Active Target -> Instance2 Build with Instance2
  1. 将在模拟器中创建您的应用程序的调试代码例如,您的应用程序名称是 - Instance
  2. 关闭模拟器
  3. 转到 Project->New Target -> Instance2 在 Instance2.info.plist 文件中添加“Bundle display name : Instance2” Set Executable Name : Instance2 选择 Instance2 Target -> Go to Project -> Set Active Target -> Instance2 Build with Instance2

Note : Do all carefully otherwise you have to reset your simulator For Reset Simulator -> Run Simulator -> iPhone Simulator -> Reset Content & Settings...

注意:请小心操作,否则您必须重置模拟器 For Reset Simulator -> Run Simulator -> iPhone Simulator -> Reset Content & Settings...

Now You have two apps in simulator and you can test app on all instance.

现在您在模拟器中有两个应用程序,您可以在所有实例上测试应用程序。

Hope it will help you :)

希望它会帮助你:)

回答by the_e

In XCode 4 you can run multiple instances while having both be in debug mode.

在 XCode 4 中,您可以运行多个实例,同时让它们都处于调试模式。

What I did was create a duplicate of my target and ran both the original and the duplicate. If you're using the output window you can toggle which output you are looking at.

我所做的是创建目标的副本并同时运行原始和副本。如果您正在使用输出窗口,您可以切换您正在查看的输出。

回答by Andrej Karadzic

I managed to get it to work combining answer by Ivstywith this one.

我设法将Ivsty 的答案与这个结合起来工作。

Basically, what you do is create two users (A and B), run simulators in each of them, run VNC server on user B, and then connect from user A to access screen B without needing to switch users.

基本上,您要做的是创建两个用户(A 和 B),在每个用户中运行模拟器,在用户 B 上运行 VNC 服务器,然后从用户 A 连接到访问屏幕 B,而无需切换用户。

回答by julien_c

Supported from Xcode 9 on.

从 Xcode 9 开始支持。

(Source: WWDC 2017)

(来源:WWDC 2017)

回答by IgnazioC

Yes, now it's possible and is also quite easy. The only thing you need is xctool, the build tools from Facebook and a ruby gem. The ruby gem helps to create/destroy the simulator needed during the test.

是的,现在可以了,而且也很容易。您唯一需要的是xctool,来自 Facebook 的构建工具和 ruby​​ gem。ruby gem 有助于创建/销毁测试期间所需的模拟器。

You can read the full documentation on this link:

您可以在此链接上阅读完整的文档:

https://github.com/plu/parallel_ios_tests

https://github.com/plu/parallel_ios_tests

I'm using this approach and I run my test on 4 iOS simulator on the same time.

我正在使用这种方法,并且同时在 4 个 iOS 模拟器上运行我的测试。