我在 iOS 模拟器中运行了一个自动化程序,我必须在下次运行之前将其删除。如何通过命令行从 iOS 模拟器中删除应用程序?
对于每个模拟器设备目录(位于
~/Library/Developer/CoreSimulator/Devices/*
),我
尝试删除 ./data/Containers/Bundle/Application/
和 ./data/Containers/Data/Application/
。
即使我尝试通过长按模拟器中的应用程序(应用程序变得不稳定)并单击 X 按钮来删除应用程序,用户默认值也没有被清除。我希望应用程序状态 100% 干净。
我找到了一个很好的解决方案来解决这个问题。
使用 Xcode 6.1,要卸载应用程序,请使用以下命令:
xcrun simctl uninstall booted com.example.apple-samplecode.UICatalog
其中
com.example.apple-samplecode.UICatalog
是您要卸载的应用程序的捆绑包标识符。
我们发现删除用户默认值的一种方法是,除了删除应用程序和数据目录之外,还删除
./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(Build 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 erase all
这将重置 Xcode 活动版本(由
xcode-select -p
引用的版本)的所有模拟器的内容和设置。
xcrun simctl uninstall simulatorIdentifier appBundleId
我知道,这是一个十年前的问题,但自那以后情况发生了变化,尽管测试干净安装的必要性仍然存在。上面的答案对我来说似乎都不太令人满意,所以我提出了另一个解决方案。
if [[ "$RUN_DESTINATION_DEVICE_PLATFORM_NAME" == "iphonesimulator" ]]; then
xcrun simctl uninstall $RUN_DESTINATION_DEVICE_UDID $PRODUCT_BUNDLE_IDENTIFIER
else
xcrun devicectl device uninstall app --device $RUN_DESTINATION_DEVICE_UDID $PRODUCT_BUNDLE_IDENTIFIER
fi
CleanInstall
:New Run Script Action
添加到 Run
阶段的 Pre-actions
:$PRODUCT_BUNDLE_IDENTIFIER
的访问权限,这在 Run
阶段是无法访问的:优点:
libmobiledevice
xcrun simctl list
,Xcode 为你提供一切xcrun simctl erase
那样完全擦除模拟器
xcrun simctl uninstall booted
不同,其中可能同时打开/连接多个设备/模拟器,并且行为可能是未定义的
xcrun simctl erase $RUN_DESTINATION_DEVICE_UDID
。但要小心真实设备!