我们发现一种删除用户默认设置的方法是删除./data/Library/Preferences/*
下的所有文件,以及删除应用和数据目录。
然而,在Xcode 6中,命令xcrun
有一个名为simctl
的新子命令,允许我管理iOS模拟器,包括重置模拟器和安装应用程序。
我想出的解决方案是使用以下命令:
xcrun simctl erase [device ID]
示例
如果 xcrun simctl list
(†) 返回
9DDA0CFE-7CEC-40B6-A343-1EC01F282B22 (active, disconnected)
Watch: Apple Watch Series 2 - 42mm (88474523-163E-4021-B591-2AECBFA26997) (Shutdown)
Phone: iPhone 7 Plus (5785E680-15CD-42D3-82AB-597286A270C5) (Shutdown)
然后运行这两个命令
xcrun simctl erase 88474523-163E-4021-B591-2AECBFA26997
xcrun simctl erase 5785E680-15CD-42D3-82AB-597286A270C5
(†) 设备 ID 可以通过运行以下命令获得
xcrun simctl list
这将重置模拟器(相当于iOS Simulator > Reset Contents and Settings... 菜单项)。
在 Xcode 6.0.1(版本号为 6A317)中,存在一个错误或行为更改,即卸载应用程序时不会删除用户默认设置。
Usage: simctl [--noxpc] [--set <set path>] <subcommand> ... | help [subcommand]
Command line utility to control the iOS Simulator
For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.
Subcommands:
create Create a new device.
delete Delete a device.
erase Erase a device's contents and settings.
boot Boot a device.
shutdown Shutdown a device.
rename Rename a device.
getenv Print an environment variable from a running device.
openurl Open a URL in a device.
addphoto Add a photo to the photo library of a device.
install Install an app on a device.
uninstall Uninstall an app from a device.
launch Launch an application by identifier on a device.
spawn Spawn a process on a device.
list List available devices, device types, or runtimes.
notify_post Post a darwin notification on a device.
icloud_sync Trigger iCloud sync on a device.
help Prints the usage for a given subcommand.
xcrun simctl uninstall booted com.example.apple-samplecode.UICatalog || true
。 - tfexcrun simctl list | grep "Booted"
。然后,您可以使用以下命令从特定的模拟器中删除应用程序:xcrun simctl uninstall [UDID] [BUNDLE_ID]
。 - Ricardo Barroso