如何在不启动 Xcode 的情况下运行 iPhone 模拟器?

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

How to run iPhone emulator WITHOUT starting Xcode?

xcodeosx-lionios-simulator

提问by E. Maggini

On my old Mac running Snow Leopard, I could type "ios" into spotlight and it would start up the iPhone/iPad emulator by itself.

在我运行 Snow Leopard 的旧 Mac 上,我可以在聚光灯下输入“ios”,它会自行启动 iPhone/iPad 模拟器。

I have since had to get a new machine running Lion. I have installed Xcode for Lion, I have installed the developer tool options from the preferences panel.

从那以后,我不得不购买一台运行 Lion 的新机器。我已经为 Lion 安装了 Xcode,我已经从首选项面板安装了开发人员工具选项。

But the "ios" option is no longer there :( The only way now seems to be to run Xcode, create an empty project and then launch emulator with the run option.

但是“ios”选项不再存在:(现在似乎唯一的方法是运行 Xcode,创建一个空项目,然后使用运行选项启动模拟器。

I have searched and searched the intertubes and the facewebs, but nothing helps.

我已经搜索并搜索了 intertubes 和 facewebs,但没有任何帮助。

Does anyone know how to run only the emulator on Lion?

有谁知道如何在 Lion 上只运行模拟器?

UPDATE: THIS IS RESPONSE TO @ike_love thread below. THAT answer is not assured to work on all Yosemite machines.

更新:这是对下面@ike_love 线程的回应。不能保证该答案适用于所有优胜美地机器。

enter image description here

在此处输入图片说明

回答by trojanfoe

Assuming you have Xcode installed in /Applications, then you can do this from the command line to start the iPhone Simulator:

假设您在 中安装了 Xcode /Applications,那么您可以从命令行执行此操作以启动 iPhone 模拟器:

$ open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app

(Xcode 6+):

(Xcode 6+):

$ open /Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app

You could create a symbolic-link from your Desktop to make this easier:

您可以从您的桌面创建一个符号链接以简化此操作:

$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app ~/Desktop

(Xcode 6+):

(Xcode 6+):

$ ln -s /Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app ~/Desktop

As pointed out by @HymanHahoney, you could also add an aliasto your ~/.bash_profile:

正如@HymanHahoney 所指出的,您还可以alias在您的~/.bash_profile:

$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/De??veloper/Applications/iPhone\ Simulator.app'

(Xcode 6+):

(Xcode 6+):

$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app'

(Xcode 7+):

(Xcode 7+):

$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'

Which would mean you could start the iPhone Simulator from the command line with one easy-to-remember word:

这意味着您可以使用一个易于记忆的单词从命令行启动 iPhone 模拟器:

$ simulator

回答by SeanDL

The easiest way without fiddling with command line:

无需摆弄命令行的最简单方法:

  1. launch Xcode once.
  2. run ios simulator
  3. drag the ios simulator icon to dock it.
  1. 启动 Xcode 一次。
  2. 运行ios模拟器
  3. 拖动 ios 模拟器图标以停靠它。

Next time you want to use it, just click on the ios simulator icon in the dock.

下次要使用时,只需单击dock 中的ios 模拟器图标即可。

回答by bcattle

In XCode 7+ the location is now

在 XCode 7+ 中,位置现在是

/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app

Run it from the command line

从命令行运行它

$ open -a Simulator

Hope that helps somebody

希望能帮助某人

回答by The iOSDev

is it helpful to you see the image enter image description here

看图对你有帮助吗 在此处输入图片说明

Edit

编辑

Now with new Xcode if the icon of the Xcode is on dock you can just right click it and form the menu you can select Open Developer Tooland in the sub menu you can select the iOS Simulatorto open the simulator without opening the Xcode.!enter image description here

现在有了新的 Xcode,如果 Xcode 的图标在 Dock 上,您只需右键单击它并形成您可以选择的菜单Open Developer Tool,在子菜单中您可以选择iOS Simulator打开模拟器而无需打开 Xcode。!在此处输入图片说明

回答by Jonathan Potter

You canget it to launch via spotlight if you create an Automator launcher for it:

可以,如果你为它创建一个Automator的启动得到它通过聚光灯推出:

  1. Open Automator.app
  2. Choose type of Application
  3. Select Actions > Library > Utilities > Launch Application
  4. Open the dropdown of applications that can be launched and choose Other
  5. You can't directly select the Simulator app because it's inside the Xcode.apppackage. So instead you'll have to navigate to it in a separate Finder window and drag it onto the file selector window. It will be at one of the following paths depending on your version of Xcode (oldest to newest):
    • /Applications/Xcode.app/Contents/Developer/iOS Simulator.app
    • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iOS Simulator.app
    • /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
  6. Finally, save this Automator app in your applications folder as iOS Simulator.app
  1. 打开 Automator.app
  2. 选择应用类型
  3. 选择操作 > 库 > 实用程序 > 启动应用程序
  4. 打开可以启动的应用程序下拉菜单,然后选择其他
  5. 您不能直接选择 Simulator 应用程序,因为它在Xcode.app包内。因此,您必须在单独的 Finder 窗口中导航到它并将其拖到文件选择器窗口中。它将位于以下路径之一,具体取决于您的 Xcode 版本(从最旧到最新):
    • /Applications/Xcode.app/Contents/Developer/iOS Simulator.app
    • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iOS Simulator.app
    • /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
  6. 最后,将此 Automator 应用程序保存在您的应用程序文件夹中 iOS Simulator.app

Create Automator app

创建 Automator 应用

To get a nice icon for the Automator app you just made, you can do the following:

要为您刚刚制作的 Automator 应用程序获得一个漂亮的图标,您可以执行以下操作:

  1. Right click iOS Simulator.appand choose Get Info
  2. Click the icon in the upper left corner and do Cmd-Cto copy it
  3. Right click your Automator app and choose Get Info
  4. Click the icon in the upper left corner and do Cmd-Vto paste
  1. 右键单击iOS Simulator.app并选择获取信息
  2. 单击左上角的图标并Cmd-C复制它
  3. 右键单击您的 Automator 应用程序并选择获取信息
  4. 点击左上角的图标并Cmd-V粘贴

Copy icon

复制图标

回答by dhr_p

No need to do anything on the commandline.

无需在命令行上执行任何操作。

Just use spotlight to run simulator.app

只需使用聚光灯运行simulator.app

screenshot of spotlight searching simulator.app

聚光灯搜索模拟器.app截图

回答by Jimothy

As the multitude of answers indicate, there are lots of different ways to address this issue. Not all of them address what is my number one issue, and what seems to be the asker's priority, as well: The ability to launch from Spotlight.

正如众多答案所表明的那样,有很多不同的方法可以解决这个问题。并非所有这些都解决了我的第一个问题,以及似乎是提问者的优先事项:从 Spotlight 启动的能力。

Here's the solution that works well for me, and should work with any OS X and XCode versions. I've tested it on OS X 10.11 and XCode 7.3.

这是对我来说效果很好的解决方案,应该适用于任何 OS X 和 XCode 版本。我已经在 OS X 10.11 和 XCode 7.3 上测试过它。

Initial setup does require launching XCode, but after that, you won't need to just to get to the Simulator.

初始设置确实需要启动 XCode,但在此之后,您将不再需要进入模拟器。

Setup

设置

  1. Launch XCode
  2. From the XCodemenu, select Open Developer Tool> Simulator
  3. In the dock, control (or right) click on the Simulator icon
  4. Select Options> Show in Finder
  5. While holding down Command and Option, drag the Simulator icon to the applications directory. This creates an alias to it.
  6. If desired, rename the alias from "Simulator" to "iOS Simulator". Whatever you name it is what it will show up as in Spotlight.
  1. 启动 XCode
  2. XCode菜单中,选择Open Developer Tool> Simulator
  3. 在 Dock 中,控制(或右键)单击模拟器图标
  4. 选择选项>在 Finder 中显示
  5. 在按住 Command 和 Option 的同时,将模拟器图标拖到应用程序目录中。这会为其创建一个别名。
  6. 如果需要,将别名从“Simulator”重命名为“iOS Simulator”。无论您命名它是什么,它都会在 Spotlight 中显示。

Note: There are other ways to get to the location of the Simulator app (steps 1-4), such as using Go to Folder…in the Finder, but those require knowing the location of the Simulator to begin with. Since that has changed from version to version of XCode, this way should work regardless of these changes.

注意:还有其他方法可以到达模拟器应用程序的位置(步骤 1-4),例如使用Finder 中的转到文件夹...,但这些方法需要知道模拟器的位置才能开始。由于 XCode 的版本已更改,因此无论这些更改如何,这种方式都应该有效。

Use

  1. Launch Spotlight (command-space, etc.)
  2. Type "simulator" or "ios" (if you renamed the alias).
  3. If necessary, use the down arrow to scroll to the Simulator alias. Eventually, spotlight should learn and make the alias the top choice so you can skip this step.
  4. Hit return
  1. 启动 Spotlight(命令空间等)
  2. 键入“simulator”或“ios”(如果您重命名了别名)。
  3. 如有必要,请使用向下箭头滚动到模拟器别名。最终,spotlight 应该学习并使别名成为首选,这样您就可以跳过这一步。
  4. 点击返回

回答by Dinesh

Try below instruction for launching iphone simulator:

尝试以下启动 iphone 模拟器的说明:

Goto Application Folder-->Xcodeapp-->right click to Show Package Contents-->now show files in xcode contents-->Developer-->Platforms-->iPhoneSimulator.platform-->Developer-->Applications--> now show iOS Simulatorapp click to launch iphone simulator...!

转到应用程序文件夹--> Xcode应用程序 --> 右键单击以显示包内容--> 现在在 xcode内容中显示文件-->开发人员-->平台--> iPhoneSimulator.platform-->开发人员-->应用程序-- > 现在显示iOS Simulator应用程序单击以启动 iphone 模拟器...!

回答by daniel

With Xcode 6 the location of the simulator has changed to:

使用 Xcode 6,模拟器的位置已更改为:

/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app

It can no longer be found here:

它不能再在这里找到:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app

I hope this helps someone since I sometimes want to start the simulator from terminal.

我希望这对某人有所帮助,因为我有时想从终端启动模拟器。

回答by M.G.

From Terminal you have to run:

从终端你必须运行:

open -a Simulator