xcode 清理 iPhone 模拟器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/692064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:59:32  来源:igfitidea点击:

Cleaning up the iPhone simulator

iphonexcodeios-simulator

提问by Travis Jensen

Is there a straightforward way to clean up the directory where xcode deploys an app when building for the iPhone simulator? I have a sqlite database that gets copied into the Documents folder on startup if necessary. The problem is that I might change my schema, but the new database won't get copied, because one already exists.

在为 iPhone 模拟器构建时,是否有一种直接的方法来清理 xcode 部署应用程序的目录?我有一个 sqlite 数据库,如果需要,它会在启动时复制到 Documents 文件夹中。问题是我可能会更改我的架构,但新数据库不会被复制,因为一个已经存在。

Ideally, every time I build, it would nuke the previous contents. Is this possible, or do I have to manually do it?

理想情况下,每次我构建时,它都会破坏以前的内容。这是可能的,还是我必须手动完成?

采纳答案by PyjamaSam

The simulator installs apps into:

模拟器将应用程序安装到:

"$HOME/Library/Application Support/iPhone Simulator/User/Applications"

Also check:

还要检查:

"$HOME/Library/Developer/CoreSimulator/Devices"

The GUID files and directories match up to the simulator's installed apps.

GUID 文件和目录与模拟器安装的应用程序匹配。

Manually delete all those files/directories to remove all applications from the simulator.

手动删除所有这些文件/目录以从模拟器中删除所有应用程序。

I know there is some way to add scripts to the build process in XCode.

我知道有一些方法可以将脚本添加到 XCode 的构建过程中。

Also it looks as if XCode changes the GUID it uses each build (the directory where my app sits changes between builds in XCode), so trying to delete the same directory all the time won't work. If you are only working on one app at a time then clearing out the entire directory would be an option.

此外,它看起来好像 XCode 更改了它使用的每个构建的 GUID(我的应用程序所在的目录在 XCode 中的构建之间发生变化),因此尝试始终删除相同的目录是行不通的。如果您一次只在一个应用程序上工作,那么清除整个目录将是一种选择。

回答by j7nn7k

From Apples Dev Resources:

来自 Apples 开发资源:

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.

要将模拟器的用户内容和设置设置为出厂状态并删除您已安装的应用程序,请选择iPhone 模拟器 > 重置内容和设置

This resembles:

这类似于:

iOS Reset

iOS 重置

回答by John

The way I do this is to simply click and hold on the icon for my app in the simulator--then when it starts to wiggle click the black and white (x). A message will pop up asking whether you really want to delete and you just click yes. The next time you build and deploy your app it will use the new sqlite db without a hitch and you don't have to go muck around in the filesystem.

我这样做的方法是在模拟器中单击并按住我的应用程序的图标 - 然后当它开始摆动时单击黑色和白色 (x)。将弹出一条消息,询问您是否真的要删除,您只需单击是。下次构建和部署应用程序时,它会顺利使用新的 sqlite 数据库,而且您不必在文件系统中到处乱跑。

回答by idStar

After iOS 5 on Mac OS X Lion, you can try:

在 Mac OS X Lion 上的 iOS 5 之后,您可以尝试:

  1. Create a script called RemoveSimulatorApps.commandthat contains:
    rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Applications/*"
    
  2. Save this script to a directory in your PATH.
  3. Make the file executable, such as:
    chmod +x RemoveSimulatorApps.command
  1. 创建一个名为的脚本RemoveSimulatorApps.command,其中包含:
    rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Applications/*"
    
  2. 将此脚本保存到PATH.
  3. 使文件可执行,例如:
    chmod +x RemoveSimulatorApps.command

Assumptions

假设

  • You may want to invoke this from a keyboard favorites buttons, such as on a Logitech or Microsoft keyboard with programmable keys (hence, saving it as a .command file instead of say, .sh)
  • You are okay with blowing away everything in the iOS simulator (ideal if you're just actively working on one app)
  • All the notes from others apply about being a good upgradable app etc. (I personally found this useful nonetheless b/c I have development mode switches that reload a database in a specific state I was trying to do some consistent robustness/error handling on)
  • 您可能希望从键盘收藏夹按钮调用它,例如在带有可编程键的 Logitech 或 Microsoft 键盘上(因此,将其保存为 .command 文件而不是 .sh)
  • 你可以把 iOS 模拟器中的所有东西都吹走(如果你只是在积极地开发一个应用程序,这是理想的)
  • 其他人的所有注释都适用于成为一个很好的可升级应用程序等(我个人发现这很有用 b/c 我有开发模式开关,可以在特定状态下重新加载数据库,我试图对其进行一些一致的健壮性/错误处理)

回答by ShoeLace

it may be overkill but..

这可能有点矫枉过正,但是..

you can also use the menu and 'Reset Content and Settings...'

您还可以使用菜单和“重置内容和设置...”

回答by mahboudz

What you are really trying to do is to clear out your database, if you've changed the schema. One way to do this, and it would make you happier in the long run when you start shipping version 2.0, 3.0, etc. of your app, is to check the version of your sqlite table, and if it has changed, then discard the old file and use the one in your bundle.

如果您更改了架构,您真正要做的是清除数据库。执行此操作的一种方法,从长远来看,当您开始发布应用程序的 2.0、3.0 等版本时,它会让您更快乐,就是检查您的 sqlite 表的版本,如果它已更改,则丢弃旧文件并使用捆绑包中的那个。

Finding a way to clean up the Simulator won't help the real world problem of how to clean up a customer's iPhone when you ship a new version with a new schema.

找到一种清理模拟器的方法无助于解决现实世界中的问题,即当您发布具有新架构的新版本时如何清理客户的 iPhone。

For extra points, after determining that you have encountered an old schema, you may want to copy the new database over without destroying the old one, and load any interesting data out of the old database, into the new one. Then blow away the old database. That way you can preserve your user's additions to the database.

额外的一点是,在确定遇到旧模式后,您可能希望在不破坏旧数据库的情况下复制新数据库,并将旧数据库中的任何有趣数据加载到新数据库中。然后吹走旧数据库。这样您就可以保留用户对数据库的添加。

回答by jia tian

for Xcode >= 6

对于 Xcode >= 6

xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -n1 xcrun simctl erase

回答by Harald

If you are using Xcode 9 -> Menubar-> Hardware-> Erase All Content and Settings

如果您使用的是 Xcode 9 ->菜单栏->硬件->擦除所有内容和设置

Xcode ->Hardware ->Erase All Content and Settings

Xcode ->硬件 ->擦除所有内容和设置

回答by Thomas T

This works with Xcode 6:

这适用于 Xcode 6:

xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -I{} xcrun simctl erase {}

For .bash_profile

对于 .bash_profile

alias cleansim="xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -I{} xcrun simctl erase {}"

回答by Jeremy Huddleston Sequoia

As of Xcode 6, you can do this from the command line with: xcrun simctl erase

从 Xcode 6 开始,您可以使用以下命令从命令行执行此操作:xcrun simctl erase

Also, the iOS Simulator app (both the Xcode 6 version and older versions) has a menu item called "Reset Content and Settings" that can be used to erase the currently booted device.

此外,iOS 模拟器应用程序(Xcode 6 版本和旧版本)有一个名为“重置内容和设置”的菜单项,可用于擦除当前启动的设备。