Reset the contents and settings all iOS-simulators

烈酒焚心 提交于 2019-11-30 12:03:00

问题


Is there any option to reset the contents and settings of all the simulators ?In a single event or a single command via command line?


回答1:


I present,

The Definitive iOS Simulator Reset Script (link)

Based on Oded Regev's code from this SO question (which was based on Jacob Rus's fine "menu_click" code)




回答2:


Based on the the answer from Jeremy Huddleston Sequoia I wrote a shell script that will reset all simulators.

For Xcode 7 you can use:

#!/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

For previous versions use:

#!/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



回答3:


With Xcode 6, you can use the simctl command line utility:

xcrun simctl erase <device UDID>

With Xcode 7, you can erase all at once with:

xcrun simctl erase all



回答4:


With Xcode 10:

#!/usr/bin/env sh

xcrun simctl shutdown all
xcrun simctl erase all



回答5:


Inspired by the answer from Daniel Wood, I came up with this one.

It solves the problem of what to do with a running simulator. Our CI environment leaves the simulator running after the tests run, and that's getting more tainted over time.

The guid detection isn't as accurate, but I think the readability trade-off is worthwhile.

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

Tested with the XCode 7.




回答6:


With the latest version of Xcode command line tools you can call xcrun simctl erase all

Make sure to quit the sim every time you call this function or you'll get an error stating An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159): Unable to erase contents and settings in current state: Booted




回答7:


you can run this command xcrun simctl erase all




回答8:


Simply go to ~/Library/Application Support/iPhone Simulator and delete all the contents out of there. The above methods don't work on iOS 7, so this seemed to work for me.




回答9:


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).

https://github.com/michaelpatzer/ResetAllSimulators




回答10:


You can call this command:

rm -rf ~/Library/Application Support/iPhone Simulator



回答11:


There is a tool xctool - https://github.com/facebook/xctool which is replacement of xcodebuild. It allows to build application from command line as well as run tests for it. Besides running tests it is allows to provide arguments such as -freshSimulator and -freshInstall that resetting content for target simulator before executing tests. That simplifies a lot resetting of simulator, as you avoiding various magic with bash scripts etc everything encapsulated within tool.




回答12:


xcrun simctl erase all
xcrun simctl delete unavailable



回答13:


To set the user content and settings of the simulator to their factory state and remove the applications you have installed, choose iPhone Simulator > Reset Content and Settings.



来源:https://stackoverflow.com/questions/15365179/reset-the-contents-and-settings-all-ios-simulators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!