How to automatically reset iPhone simulator on bui

2020-06-23 08:07发布

问题:

After moving several JSON files from the app bundle root to within a directory structure (also in the app bundle) the app kept running as if the files remained in their prior location. After much head scratching and doing a clean build I remembered that the iPhone simulator had to be cleared out in order to get rid of these files in the old locations.

It'd sure be nice to have the option to force a reset of the simulator on every build. Clean-slate mode, if you will. Can this be hacked in any way? Any ideas?

回答1:

You can add a "New Run Script Action" to the "Pre-actions" for the "Run" step of your scheme to run AppleScript that will reset the simulator.

First set the shell to /usr/bin/osascript

Then enter the following in the "type a script" area:

#!/usr/bin/env osascript

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


回答2:

In Yosemite + iOS Simulator 8.3, It worked when I changed the Vic's strings of "iPhone Simulator" and "iOs Simulator" to "iOS Simulator".