Xcode 8 / xcodebuild:如何触发'更新签名'从命令行?

时间:2016-10-18 16:16:41

标签: xcode xcodebuild

背景:Xcode 8具有“自动更新签名”的新功能。由于构建mac上没有配置文件,Xcode将自动从Apple开发门户中提取所需的配置文件。 然后可以rm -rf ~/Library/MobileDevice/Provisioning\ Profiles打开Xcode项目,Xcode会自动提取配置文件,人们会看到更新签名'在Xcode:

xcode update signing message

如何触发此操作'更新签名'从命令行? xcodebuild的手册页没有提到这一点。只需运行' xcodebuild'不会执行此步骤。

1 个答案:

答案 0 :(得分:1)

使用xcodebuild无法执行此操作。

但是,我有一个解决方案似乎正在为我完成任务。我使用AppleScript在Xcode中打开工作区,等待适当的时间(比如说10秒),然后退出Xcode。签名更新在工作区打开时完成,而不是在您尝试构建时完成,因此这足以解决任何签名问题。

我使用的AppleScript就是这个(基于我在互联网上找到的一些代码):

tell application "/Applications/Xcode.app"

    open "/Users/gary/MyWorkspace.xcworkspace"
    set workspaceDocument to workspace document "MyWorkspace.xcworkspace"
    -- Wait for the workspace document to load with a 60 second timeout
    repeat 120 times
        if loaded of workspaceDocument is true then
            exit repeat
        end if
        delay 0.5
    end repeat
    if loaded of workspaceDocument is false then
        error "Xcode workspace did not finish loading within timeout."
    end if

    -- Xcode will only update the signing for targets in the active scheme,
    -- so make sure the required scheme is the active one
    set schemeToUse to scheme "SchemeToUse" of workspaceDocument
    set active scheme of workspaceDocument to schemeToUse

    -- The time taken to update signing issues is related to the number of targets.
    -- The number of targets built by a scheme is not exposed through AppleScript,
    -- so count the total number of targets in the workspace 
    set totalTargets to 0
    repeat with theProject in projects in workspaceDocument
        set totalTargets to totalTargets + (count of targets of theProject)
    end repeat

    -- For each target, wait a short amount of time
    repeat totalTargets times
        delay 3.0
    end repeat

    quit

end tell

您需要更改工作区的工作区路径,工作区名称和方案名称。

有许多方法可以从命令行运行AppleScript,包括osascript命令,但我一直在使用Python。