【发布时间】:2016-09-27 19:15:24
【问题描述】:
我想在测试结束时退出脚本中的应用。
我知道command+shift+hh 可以退出模拟器中的应用程序,但我想通过命令行退出。
有什么好的方法可以解决我的问题吗?
【问题讨论】:
-
提供有问题的代码,而不是截图。
标签: xcode ios-simulator instruments
我想在测试结束时退出脚本中的应用。
我知道command+shift+hh 可以退出模拟器中的应用程序,但我想通过命令行退出。
有什么好的方法可以解决我的问题吗?
【问题讨论】:
标签: xcode ios-simulator instruments
从命令行,您可以使用 kill 命令向进程发送 SIGTERM 或 SIGKILL:
kill <pid>
kill -9 <pid>
【讨论】:
simulator 进程而不是应用程序本身
我尝试了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
【讨论】:
我喜欢以下:
# 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
【讨论】: