一个人如何在多个目的地(比如iPhone、iPad和iSimulator)一次运行一个项目?
有2个相关问题:
1ˢᵗ 问题(据说)有答案,但我无法弄清楚究竟你应该使用
Aggregate
目标(如果这是正确的方向),显然 Josh Kahane 也不能,手术室; “答案”仍然以某种方式得到/保持接受。
2ⁿᵈ 问题被关闭为“重复”,就好像 1ˢᵗ 提供了一个(可行的)答案一样。
增加了赏金:(如何)一个人可以同时使用
Aggregate
目标,多个Build & Run
?也许可以通过使用 Build & Run
的一些 .sh
脚本同时实现多个 xcodebuild
?还有其他可能的解决方案吗?
更新:Apple 从 Xcode 8 开始删除了对此类插件的支持。AppleScript 可能是您最好的选择。
我遇到了同样的问题,所以我写了一个 Xcode 插件来帮助解决这个问题。我发现它比 AppleScript 选项更强大且更容易调用。
该插件称为 KPRunEverywhereXcodePlugin,可通过 Alcatraz 或 GitHub 获得:https://github.com/kitschpatrol/KPRunEverywhereXcodePlugin
希望这有帮助!
其实比我想象的要简单。这
AppleScript
消除了一些痛苦 Xcode
:
tell application "Xcode"
activate
end tell
tell application "System Events"
tell application process "Xcode"
click menu item "1st iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
delay 5
click menu item "2nd iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
delay 5
click menu item "iPhone 6.1 Simulator" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
end tell
end tell
AppleScript
保存为.app
。 (为您的机器定制delay
s。)Service
in Automator
: choose Launch Application
and select the .app
from previous step.Service
并给它一个键盘快捷键。提示:避免使用 ^ 快捷方式,因为它会弹出此对话框:
当然,这不是严格意义上的 simultaneous “构建和运行”,但它肯定比在目的地之间手动微调要好。
这里是一个将在所有连接的 iOS 设备上构建和运行的脚本。使用:
Javascript:
function run(input, parameters)
{
var xcode = Application("Xcode");
var ws = xcode.activeWorkspaceDocument();
var genericDest = null;
var devices = [];
ws.runDestinations().forEach(function(runDest)
{
if (runDest.platform() != "iphoneos")
return;
if (runDest.device().generic())
{
genericDest = runDest;
}
else
{
devices.push(runDest);
}
});
devices.forEach(function(device)
{
ws.activeRunDestination = device;
var buildResult = ws.run();
while (true)
{
if (buildResult.completed())
break;
if (buildResult.buildLog() && buildResult.buildLog().endsWith("Build succeeded\n"))
break;
delay(1);
}
delay(1);
});
}
使用 Xcode 一次上传多个文件确实很好。然而据我了解,
aggregate
只允许你编译多个目标,而不是运行它们。
考虑到您问题的第二部分(编辑后),我可以为您指出另一种方法。您不会附加 xcode(但 gdb 处于控制台模式)并且您应该能够在多个设备上同时执行它,尽管这不是主要目标。这个特定的解决方案不适用于模拟器,但还有其他方法。
这是一个脚本,它将运行您的产品 -> 目标菜单中当前可用的所有设备。注意:它依赖于以下条件:
设备后的菜单项名为“iOS Simulator”(猜猜什么时候会改变?)
tell application "Xcode"
activate
end tell
tell application "System Events"
tell process "Xcode"
set deviceMenu to menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
set allUIElements to entire contents of deviceMenu
set startAfterName to "My Mac 64–bit"
set stopName to "iOS Simulator"
set started to false
repeat with anElement in allUIElements
try
set menuName to name of anElement
if menuName is equal to stopName then
set started to false
exit repeat
else if menuName is equal to startAfterName then
set started to true
else if started then
click menu item menuName of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
delay 5
end if
end try
end repeat
end tell
end tell