如何在 Xcode 中一次在多个目的地“构建和运行”?

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

一个人如何在多个目的地(比如iPhone、iPad和iSimulator)一次运行一个项目? Xcode Product optionsXcode multiple destinations


有2个相关问题:

  1. Xcode 4 - 一键构建到多个设备?
  2. 模拟器和手机一键运行

1ˢᵗ 问题(据说)有答案,但我无法弄清楚究竟你应该使用

Aggregate
目标(如果这是正确的方向),显然 Josh Kahane 也不能,手术室; “答案”仍然以某种方式得到/保持接受。

2ⁿᵈ 问题被关闭为“重复”,就好像 1ˢᵗ 提供了一个(可行的)答案一样。


增加了赏金:(如何)一个人可以同时使用

Aggregate
目标,多个
Build & Run
?也许可以通过使用
Build & Run
的一些
.sh
脚本同时实现多个
xcodebuild
?还有其他可能的解决方案吗?

iphone ipad build ios-simulator xcode5
5个回答
15
投票

更新:Apple 从 Xcode 8 开始删除了对此类插件的支持。AppleScript 可能是您最好的选择。

我遇到了同样的问题,所以我写了一个 Xcode 插件来帮助解决这个问题。我发现它比 AppleScript 选项更强大且更容易调用。

该插件称为 KPRunEverywhereXcodePlugin,可通过 Alcatraz 或 GitHub 获得:https://github.com/kitschpatrol/KPRunEverywhereXcodePlugin

New menu items

希望这有帮助!


11
投票

其实比我想象的要简单。这

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
  1. 将上面的
    AppleScript
    保存为
    .app
    。 (为您的机器定制
    delay
    s。)
  2. Create a new
    Service
    in
    Automator
    : choose
    Launch Application
    and select the
    .app
    from previous step.
  3. 从上一步保存
    Service
    并给它一个键盘快捷键。提示:避免使用 ^ 快捷方式,因为它会弹出此对话框: enter image description here

当然,这不是严格意义上的 simultaneous “构建和运行”,但它肯定比在目的地之间手动微调要好。


4
投票

这里是一个将在所有连接的 iOS 设备上构建和运行的脚本。使用:

  1. 打开“Automator”。
  2. 创建一个新的“快速操作”。
  3. 为“工作流程接收”选择“无输入”。
  4. 为应用程序选择 Xcode。
  5. 添加“运行 JavaScript”操作并粘贴脚本。
  6. 另存为“Run on All”,您现在可以从 Xcode 的 Xcode -> Services 菜单访问它。

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);
    });
}

1
投票

使用 Xcode 一次上传多个文件确实很好。然而据我了解,

aggregate
只允许你编译多个目标,而不是运行它们。

考虑到您问题的第二部分(编辑后),我可以为您指出另一种方法。您不会附加 xcode(但 gdb 处于控制台模式)并且您应该能够在多个设备上同时执行它,尽管这不是主要目标。这个特定的解决方案不适用于模拟器,但还有其他方法。

从 Mac OS X 控制台启动 iOS 应用


0
投票

这是一个脚本,它将运行您的产品 -> 目标菜单中当前可用的所有设备。注意:它依赖于以下条件:

  1. 设备从 Product -> Destination 菜单中选择(在未来的 Xcode 版本中可能会改变)
  2. 设备前的菜单项名为“我的 Mac 64 位”(可能会在 Xcode 的未来版本中更改)
  3. 设备后的菜单项名为“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
    
© www.soinside.com 2019 - 2024. All rights reserved.