如何从命令行重置 iOS 模拟器?
我需要经常重置 iPhone 模拟器,但还没有找到不使用鼠标的方法。这是一件小事,但我真的厌倦了这样做,并且希望有一种方法可以使用键盘快捷键来完成此操作。
更好的是从命令行重置它,这样我就可以将重置构建到部署脚本中。
我对 iOS 或 MacOS 不太熟悉。
I need to reset the iPhone Simulator a lot, and haven't found a way to do it without using the mouse. It's a small thing, but I'm really sick of doing it and would love to have a way to do this using a keyboard shortcut.
Even better would be a way to reset it from the command line, so I could build a reset into a deploy script.
I am not very familiar with iOS or MacOS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
只需在终端中运行此命令:
@txulu 建议的另一种方法,在删除模拟器之前终止进程:
Just run this in the terminal:
Another approach suggested by @txulu, before erasing the simulator kill the process:
在 Xcode 6 中,不要只删除模拟器的文件夹!它会把事情搞砸,而且会让你头疼。
在 Xcode 6 中,实际上有一个工具可以从命令行控制模拟器。
确保您的命令行设置设置为 Xcode 6
在 Xcode 6 中,每个设备都有一个与其关联的 GUID/UUID,要重置特定设备,您需要它的 GUID。
该命令
将显示您已设置的所有设备。输出将如下所示:
只需复制括号内的 GUID,然后运行 xcrun simctl freeze
例如,
将擦除 iOS 7.0、iPhone 5 设备
In Xcode 6, DO NOT JUST DELETE THE FOLDER FOR THE SIMULATOR! It WILL screw things up, and it WILL cause you a headache.
In Xcode 6, there's actually a tool to control the simulator from the command line.
Make sure your command line settings are set to Xcode 6
In Xcode 6, each device has a GUID/UUID associated to it, to reset a specific device, you need the GUID for it.
The command
will show you all of the devices you have set up. The output will look like this:
Just copy the GUID from inside the parentheses, and run
xcrun simctl erase
for example,
would erase the iOS 7.0, iPhone 5 device
我想我会把这篇文章发布给任何遇到同样需求的人。 reddit 上有人给了我这个解决方案(我测试过,效果很好)。请注意,这次“Settings”后面需要一个省略号,而不是三个句点(很奇怪)。
这是一个 AppleScript,可以从命令行调用来重置模拟器:
另存为
/path/to/script
并使用以下命令调用:Thought I'd post this for anyone who runs into the same need. Someone on reddit gave me this solution (which I tested and it works great). Note that this time you need an ellipsis after "Settings", not three periods (weird).
This is an AppleScript that can be invoked from the command line to reset the Simulator:
Save as
/path/to/script
and invoke with:我用XCode 9检查过。
要关闭所有活动模拟器,请运行:
要重置所有模拟器,请运行:
您可以像这样过滤要关闭/重置的模拟器:
在您的计算机上查找所有可访问的模拟器(及其 GUID),如下所示:
要按 GUID 运行任何模拟器:
要安装应用程序到启动的模拟器:
要从启动的模拟器中删除应用程序:
要在启动的模拟器中启动应用程序:
“com.app.bundleIdentifier”是 Info.plist 中的 CFBundleIdentifier
I checked it with XCode 9.
To close all active simulators run:
To reset all simulators run:
You can filter what simulator to close/reset like this:
Find all accessible simulators (and their GUID) on your machine like this:
To run any simulator by GUID:
To install app to the booted simulator:
To remove app from the booted simulator:
To launch the app in the booted simulator:
"com.app.bundleIdentifier" is your CFBundleIdentifier in Info.plist
复制粘贴答案 - 注意:将重置所有可用模拟器的内容和设置。
感谢@Alpine 的灵感和知识。如果您在命令行中运行此命令,您应该能够重置所有可用的模拟人生。这适用于 Xcode 6。
COPY-PASTE ANSWER - note: will reset the contents and settings of all available simulators.
Thanks @Alpine for the inspiration and knowledge. If you run this in your command line you should be able to reset all the available sims. This works with Xcode 6.
删除 的内容
就可以了。
Delete the contents of
And you're good to go.
安装 Xcode 后,我总是在模拟器中创建“重置内容和设置”的键盘快捷键。非常有用的节省时间的工具。
系统偏好设置>键盘>快捷方式>应用程序快捷方式> “+”
在应用程序选择器中,选择“其他...”以打开应用程序选择器对话框。
在此对话框中,您无法“显示包内容”来浏览 .app,因此您需要通过 Cmd-Shift 使用
转到文件夹
-G。 (首先打开应用程序下拉列表并选择其他
)在当前版本的Xcode中,转到路径:
/Applications/Xcode/Contents/Developer/Applications
选择
Simulator.app
并按“添加”对于
菜单标题
,输入重置内容和设置...
对于
键盘快捷键
,按 CMD-Shift-RUpon installing Xcode I always create a keyboard shortcut for "Reset Content and Settings" in the simulator. An extremely useful time saver.
System Preferences > Keyboard > Shortcuts > App Shortcuts > "+"
In the Application picker, select "Other..." to open the app picker dialog.
In this dialog you're unable to "Show Package Contents" to explore a .app, so you'll need to use
Go to Folder
via Cmd-Shift-G. (First open the application drop down and selectOther
)In the current version of Xcode, go to the path:
/Applications/Xcode/Contents/Developer/Applications
Select
Simulator.app
and press "Add"For
Menu Title
, enterReset Content and Settings...
For
Keyboard Shortcut
, press CMD-Shift-R键盘快捷键解决方案不再相关,不幸的是@Cameron解决方案对我也不起作用(我尝试调试它但没有运气)
以下是对我有用的方法:
The keyboard short-cut solution is not relevant anymore and unfortunately @Cameron solution didn't work for me either (I tried to debug it with no luck)
Here is what works for me:
我写了一个脚本来重置内容和内容iOS 模拟器所有版本和设备的设置。它从菜单中获取设备名称和版本号,因此它将包括 Apple 为其发布模拟器的任何新设备或 iOS 版本。
手动运行或在构建脚本中使用很容易。我建议在构建之前将其添加为预操作运行脚本。
它很大程度上基于 Stian 的脚本,但不会因新的 iOS 版本而变得过时,并且消除了对话框(更适合自动化构建脚本和从命令行工作)。
https://github.com/michaelpatzer/ResetAllSimulators
I wrote a script that will reset the contents & settings of all versions and devices for the iOS Simulator. It grabs the device names and version numbers from the menu, so it will include any new devices or iOS versions that Apple releases simulators for.
It's easy to run manually or use in a build-script. I would suggest adding it as a Pre-Action Run Script before the build.
It's based heavily on Stian's script above, but doesn't become stale with new iOS versions, and eliminates the dialog box (better for automation build scripts and working from the command-line).
https://github.com/michaelpatzer/ResetAllSimulators
我发现这个非常有用的工具称为“SimulatorManager”:
http://tue-savvy.github.io
它将通过菜单栏小部件(不确定这是否是它的名称)来重置所有模拟器,但最重要的是,它将使您可以快速访问所有应用程序数据。我真的不能再没有它了。
传播这个词!
I have found this very helpful tool called "SimulatorManager":
http://tue-savvy.github.io
It will reset all you simulators by means of a menu bar widget (not sure if that's what its called) but on top of that it will give you quick access to all your application data. I really can't live without it anymore.
Spread the word!
我想在卡梅伦·布朗的回答中添加一些内容。为了确保重置正确的版本(例如,iPad,版本 6.1),我通过 ios 启动 iOS 模拟器-sim:
$DESTINATION
可以是例如"OS=7.0,name=iPad"
。为了使其正常工作,我对reset_simulator.applescript进行了一些调整并删除了激活部分:
I want to add something to Cameron Brown's answer. To make sure the correct version is resetted (e.g, iPad, version 6.1), I start the iOS Simulator via ios-sim:
$DESTINATION
can be e.g"OS=7.0,name=iPad"
.For that to work correctly, I adapted the reset_simulator.applescript a bit and removed the activation part:
作为使用 xcrun 命令的额外好处,您可以在列出后启动设备,
一旦显示列表,运行:
As an added bonus to using the xcrun commands you can launch a device after you listed with
Once you have the list displayed run:
我们使用以下 python 脚本来重置构建服务器上的模拟器。
它假设您的应用程序的包标识符设置为环境变量,例如,
您可能希望以其他方式传递包标识符。
We use the following python script to reset the simulator on our build server.
It assumse your app's bundle identifier is set as an environment variable, e.g.
maybe you'd want to pass the bundle identifier in another way.
基于上面的大多数答案,我使用 Keyboard Maestro 并制作了一个小宏来重置当前运行的模拟器并重新启动它。
重置并重新启动后,它将焦点返回到 Xcode,因此我可以立即再次点击 Command+R 来重新运行应用程序,我觉得这非常方便。
ruby脚本的内容是:
Building on most of the answers above, I am using Keyboard Maestro and made a little Macro to reset the currently running Simulator and restarting it.
It turns the focus back to Xcode after resetting and restarting, so I can hit
Command+R
again right away to re-run the app, which I find very convenient.The content of the ruby script is:
这是一个用于重置目标模拟器的 Rakefile 任务。这适用于 Xcode 7,因为 Xcode 7 命令行工具破坏了 xcrun simctl uninstall 命令。我有一个自定义的 runC 方法,因为我喜欢查看实际的终端命令及其输出。
Here's a Rakefile task to reset a targeted simulator. This works with Xcode 7 since the Xcode 7 command line tools broke the xcrun simctl uninstall command. I have a little custom runC method since I like to see the actual terminal command as well as its output.
只需一个线性命令:循环遍历设备文件夹中的每个模拟器并删除。
将其粘贴到终端中,然后按返回。
分解:
Just one liner command : Loop through each simulator in Devices folder and erase.
paste it in Terminal and hit return.
Breaking it down:
目标名称和模拟器应用程序名称似乎已更改为 xCode6 / iOS8。
这是 Cameron Brown 的 osascript for xCode6 / iOS8 的未更新版本:
target names and Simulator app name seem to have changed a bit to xCode6 / iOS8.
Here is un updated version of Cameron Brown's osascript for xCode6 / iOS8:
我介绍
最终的 iOS 模拟器重置脚本(链接)
I present,
The Definitive iOS Simulator Reset Script (link)