重置所有iOS模拟器的内容和设置

Lit*_*T.V 16 iphone ipad ios-simulator

是否有任何选项可以重置所有模拟器的内容和设置?在单个事件中还是通过命令行执行单个命令?

Dan*_*ood 40

基于Jeremy Huddleston Sequoia的回答,我写了一个shell脚本,它将重置所有模拟器.

对于Xcode 7,您可以使用:

#!/bin/sh

instruments -s devices \
| grep "(\d[.0-9]\+) \[[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}\]" \
| grep -o "[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}" \
| while read -r line ; do
    echo "Reseting Simulator with UDID: $line"
    xcrun simctl erase $line
done
Run Code Online (Sandbox Code Playgroud)

对于以前的版本使用:

#!/bin/sh

instruments -s devices \
 | grep Simulator \
 | grep -o "[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}" \
 | while read -r line ; do
    echo "Reseting Simulator with UDID: $line"
    xcrun simctl erase $line
done
Run Code Online (Sandbox Code Playgroud)


Jer*_*oia 17

使用Xcode 6,您可以使用simctl命令行实用程序:

xcrun simctl erase <device UDID>
Run Code Online (Sandbox Code Playgroud)

使用Xcode 7,您可以一次删除所有:

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


Rud*_*vič 6

使用Xcode 10:

#!/usr/bin/env sh

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


Dan*_*ley 5

受到Daniel Wood的回答的启发,我想到了这个。

它解决了如何使用正在运行的模拟器的问题。在测试运行之后,我们的CI环境使模拟器继续运行,并且随着时间的流逝,这种污染越来越严重。

guid检测的准确性不高,但是我认为值得权衡取舍。

#!/bin/bash
xcrun simctl list | grep Booted | grep -e "[0-9A-F\-]\{36\}" -o | xargs xcrun simctl shutdown
xcrun simctl erase all
Run Code Online (Sandbox Code Playgroud)

经过XCode 7测试。


Las*_*awk 5

使用最新版本的Xcode命令行工具,您可以调用 xcrun simctl erase all

确保每次调用此函数时退出SIM卡,否则您将收到错误消息 An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159): Unable to erase contents and settings in current state: Booted


Ign*_*ioC 5

你可以运行这个命令 xcrun simctl erase all