Reset iOS Simulator application data to run app for first time

半世苍凉 提交于 2019-11-27 05:23:33

问题


I just finished writing some code that checks if it is the first time the app is running then display a message, if it is not the first time then display another message..

How do you reset the simulator on Xcode so that I can test the app when it runs the first time?

I tried cleaning the build folder but it didn't work..


回答1:


In the iOS Simulator, press iOS Simulator in the menu at the top of the screen, and press 'Reset Content and Settings...'. This will clear the entire simulator.

Or, on the home screen of the simulator, uninstall the app in the same way you would on a physical device, by pressing and holding on the application icon until an 'x' appears in the top left, and press the 'x', and select 'Delete' from the alert view. This will clear all data associated with a single app.

Then do a clean, build and run.




回答2:


The correct way to do this in XCode is: (Simulator must be shut down first)

xcrun simctl erase <device UDID> or xcrun simctl erase all

To find out the UDID use:

xcrun simctl list




回答3:


Currently (Simulator Version 10.0), you can do it the following way:

Hardware > Erase All Content and Settings...




回答4:


@Tim's answer is probably easier for interactive usage.

We use scripts for automated testing and delete the simulator's data directory to ensure it's clean. The simulator will re-create basic information when it restarts.

Delete the following:

~/Library/Application Support/iPhone Simulator/${simulator.version}




回答5:


Don't really know if this is the best way but following is working for me:

first kill all working Simulators with

killall Simulator 2>&- && sleep 5 || true

afterwards reset all devices with

xcrun simctl erase all

ps.: I'm working with XCode 8



来源:https://stackoverflow.com/questions/16195859/reset-ios-simulator-application-data-to-run-app-for-first-time

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