如何通过命令行关闭ios模拟器中的应用程序

问题描述 投票:0回答:3

我想在测试结束时退出脚本中的应用程序。 我知道

command+shift+hh
可以退出模拟器中的应用程序,但我想通过命令行退出。

code

有什么好的方法可以解决我的问题吗?

xcode ios-simulator instruments
3个回答
2
投票

我喜欢下面的:

# set you bundle identifier
bundle_id=<com.myapp>
# find running device
device=$(xcrun simctl list | grep 'Booted' | awk -F'[()]+' '{print $2}')
# terminate it
xcrun simctl terminate $device $bundle_id

1
投票

从命令行,您可以使用kill命令向进程发送SIGTERM或SIGKILL:

kill <pid>
kill -9 <pid>

0
投票

我尝试了

xcrun simctl help
,有一个
terminate
动作:
xcrun simctl <SIMULATOR_ID> <BUNDLE_IDENTIFIER>
。 当您使用它时,该应用程序仍然会显示为好像在后台,但就像您单击 xcode 中的“停止”按钮一样。

如果您希望将其作为自动化过程的一部分,您也可以终止模拟器,如果这满足您的需求,

xcrun simctl shutdown <SIMULATOR_ID>

您还可以使用命令

xcrun simctl boot <SIMULATOR_ID>

重新打开模拟器

当模拟器运行时,您可以放置

booted
而不是
<SIMULATOR_ID>
,这将影响所有正在运行的模拟器。 运行应用程序是通过
xcrun simctl launch <SIMULATOR_ID> <BUNDLE_ID>

完成的

这篇博文涵盖了以上所有内容:https://medium.com/xcblog/simctl-control-ios-simulators-from-command-line-78b9006a20dc

© www.soinside.com 2019 - 2024. All rights reserved.