如何从命令行重置iOS模拟器?

Cam*_*own 60 workflow simulator ios

我需要重置iPhone模拟器,并且没有找到一种方法来不使用鼠标.这是一件小事,但我真的厌倦了这样做,并希望有一种方法来使用键盘快捷方式.

更好的方法是从命令行重置它,所以我可以在部署脚本中构建重置.

我对iOS或MacOS不太熟悉.

Kap*_*ppe 81

简单:

xcrun simctl erase all
Run Code Online (Sandbox Code Playgroud)

@txulu提出的改进,只需在执行clean之前杀死模拟器:

killall "Simulator" 2> /dev/null; xcrun simctl erase all
Run Code Online (Sandbox Code Playgroud)

  • 你需要更多的赞成.但是改进了:`killall'模拟器"2>/dev/null; xcrun simctl擦除所有` (2认同)

Alp*_*ine 55

在Xcode 6中,不要只为模拟器删除文件夹!它会搞砸,这会让你头疼.

在Xcode 6中,实际上有一个工具可以从命令行控制模拟器.

确保命令行设置设置为Xcode 6

xcrun simctl
Run Code Online (Sandbox Code Playgroud)

在Xcode 6中,每个设备都有一个与之关联的GUID/UUID,要重置特定设备,您需要GUID.

命令

xcrun simctl list
Run Code Online (Sandbox Code Playgroud)

将显示您已设置的所有设备.输出将如下所示:

== Devices ==
-- iOS 7.0 --
iPhone 4s (F77DC0AE-6A6D-4D99-9936-F9DB07BBAA82) (Shutdown)
iPhone 5 (5B78FC0D-0034-4134-8B1F-19FD0EC9D581) (Shutdown)
iPhone 5s (569E5910-E32D-40E2-811F-D2E8F04EA4EF) (Shutdown)
iPad 2 (451DBBD8-A387-4E77-89BF-2B3CD45B4772) (Shutdown)
iPad Retina (2C58366B-5B60-4687-8031-6C67383D793F) (Shutdown)
iPad Air (50E03D3B-3456-4C49-85AD-60B3AFE4918B) (Shutdown)
-- iOS 7.1 --
-- iOS 8.0 --
iPhone 4s (27818821-A0BB-496E-A956-EF876FB514C2) (Shutdown)
iPhone 5 (6FBAA7E2-857C-432A-BD03-980D762DA9D2) (Shutdown)
iPhone 5s (7675C82B-DE49-45EB-A28D-1175376AEEE9) (Shutdown)
iPad 2 (836E7C89-B9D6-4CC5-86DE-B18BA8600E7B) (Shutdown)
iPad Retina (EFDD043D-2725-47DC-A3FF-C984F839A631) (Shutdown)
iPad Air (9079AD6C-E74D-4D5F-9A0F-4933498B852E) (Shutdown)
Resizable iPhone (943CFEDE-A03C-4298-93E3-40D0713652CB) (Shutdown)
Resizable iPad (DBA71CA5-6426-484B-8E9B-13FCB3B27DEB) (Shutdown)
Run Code Online (Sandbox Code Playgroud)

只需从括号内复制GUID,然后运行即可 xcrun simctl erase

例如,

xcrun simctl erase 5B78FC0D-0034-4134-8B1F-19FD0EC9D581
Run Code Online (Sandbox Code Playgroud)

将擦除iOS 7.0,iPhone 5设备

  • xCode 7也有一个'all`参数.所以你可以用`xcrun simctl erase all`擦除所有模拟器 (7认同)
  • 如果您没有注意到 Alpine 的警告并决定从正在运行的服务下删除路径,您可以通过杀死正在运行的 CoreSimulatorService(您需要 SIGKILL)或重新启动来恢复。 (2认同)
  • 这个答案应该被赞成,因为这是最新的解决方案 (2认同)

Cam*_*own 37

以为我会为遇到同样需要的人发布这个.reddit上的某个人给了我这个解决方案(我测试了它并且效果很好).请注意,这次在"设置"之后需要省略号,而不是三个句点(奇怪).

这是一个AppleScript,可以从命令行调用以重置模拟器:

tell application "iPhone Simulator"
    activate
end tell

tell application "System Events"
    tell process "iPhone Simulator"
        tell menu bar 1
            tell menu bar item "iOs Simulator"
                tell menu "iOs Simulator"
                    click menu item "Reset Content and Settings…"
                end tell
            end tell
        end tell
        tell window 1
            click button "Reset"
        end tell
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)

保存/path/to/script并调用:

osascript /path/to/script
Run Code Online (Sandbox Code Playgroud)

  • 如果您收到"系统事件出错:禁用辅助设备访问权限.",请确保在"通用访问"下的"系统偏好设置"下启用它. (6认同)

Joe*_*ick 16

COPY-PASTE ANSWER - 注意:将重置所有可用模拟器的内容和设置.

感谢@Alpine的灵感和知识.如果您在命令行中运行它,您应该能够重置所有可用的SIM卡.这适用于Xcode 6.

# Get the sim list with the UUIDs
OUTPUT="$(xcrun simctl list)"
# Parse out the UUIDs and saves them to file
echo $OUTPUT | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$' > output.txt
# Iterate through file and reset sim
for UUID in `awk '{ print $1 }' output.txt`
do
xcrun simctl erase $UUID
done
Run Code Online (Sandbox Code Playgroud)

  • 谢谢.我做了一行`xcrun simctl list | awk -F"[()]"'{for(i = 2; i <NF; i + = 2)print $ i}'| grep'^ [ - A-Z0-9]*$'| xargs -I uuid xcrun simctl erase uuid` (8认同)

jdc*_*jdc 11

删除内容

~/Library/Application Support/iPhone Simulator/<sdk revision>
Run Code Online (Sandbox Code Playgroud)

你很高兴去.


LGF*_*Fox 9

我用XCode 9检查了它.要关闭所有活动的模拟器,请运行:

xcrun simctl shutdown all
Run Code Online (Sandbox Code Playgroud)

要重置所有模拟器运行:

xcrun simctl erase all
Run Code Online (Sandbox Code Playgroud)

您可以过滤关闭/重置的模拟器,如下所示:

xcrun simctl shutdown F36B238F-3ED6-4E10-BB5A-0726151916FA
xcrun simctl erase F36B238F-3ED6-4E10-BB5A-0726151916FA
Run Code Online (Sandbox Code Playgroud)

在您的计算机上查找所有可访问的模拟器(及其GUID),如下所示:

xcrun instruments -s
Run Code Online (Sandbox Code Playgroud)

要通过GUID运行任何模拟器:

xcrun instruments -w F36B238F-3ED6-4E10-BB5A-0726151916FA -t Blank
Run Code Online (Sandbox Code Playgroud)

要将应用程序安装到启动的模拟器:

xcrun simctl install booted /path/to/your.app
Run Code Online (Sandbox Code Playgroud)

要从启动的模拟器中删除应用程序:

xcrun simctl uninstall booted /path/to/your.app
Run Code Online (Sandbox Code Playgroud)

要在启动的模拟器中启动应用程序:

xcrun simctl launch booted "com.app.bundleIdentifier"
Run Code Online (Sandbox Code Playgroud)

"com.app.bundleIdentifier"是Info.plist中的CFBundleIdentifier


pka*_*amb 5

安装Xcode后,我总是在模拟器中为“重置内容和设置”创建键盘快捷键。一个非常有用的节省时间的工具。

System Preferences > Keyboard > Shortcuts > App Shortcuts > "+"

在“应用程序选择器”中,选择“其他...”以打开应用程序选择器对话框。

在此对话框中您无法“显示包内容”,探索一个名为.app,所以你需要使用Go to Folder通过Cmd- - 。Shift G(首先打开应用程序下拉菜单,然后选择Other

在当前版本的Xcode中,转到路径:

/Applications/Xcode/Contents/Developer/Applications

选择Simulator.app并按“添加”

对于Menu Title,输入Reset Content and Settings...

对于Keyboard Shortcut,按CMD- Shift-R

重置内容和设置