在 Xcode 9 中构建时更改 AppIcon

Via*_*hko 3 xcode imagemagick ios xcode9

我使用脚本在构建时生成应用程序图标(只需为调试模式添加“开发”标题)。使用 ImageMagick 和 Ghostscript(谷歌中有很多例子)非常容易。在我开始使用新的 Xcode 9 之前一切正常。现在,我可以在 MyAppName.app 文件上看到更新的图标,但模拟器/设备显示来自资产的 AppIcon。有什么建议?谢谢

Pet*_*ger 5

看起来,当 Xcode9 构建应用程序时,它现在将应用程序图标从资产目录复制为私有格式,并且不直接使用捆绑包中的应用程序图标文件。这可能与新的 iOS11 功能有关,您可以在运行时更改应用程序图标。

有一个简单的修复。您需要做的是直接在资产目录中更改应用程序图标,因此必须在构建设置中进行 2 项更改:

1. step - 更新运行脚本阶段

更新您的“生成图标”运行脚本构建阶段,以便更新的图标不会复制到目标包,而是在资产目录中更改图标。这是我的生成脚本的示例,请注意target_path=$base_path以下行:

function processIcon() {
    export PATH=$PATH:/usr/local/bin
    base_file=$1
    base_path=`find ${SRCROOT}/Cards/Assets.xcassets -name $base_file`

    if [[ ! -f ${base_path} || -z ${base_path} ]]; then
    echo "failed to find base_path for $base_file"
    return -1;
    fi

    target_file=`echo $base_file`

    #this is the change
    target_path=$base_path

    echo $target_path

    width=`identify -format %w ${base_path}`

    convert -background '#0008' -fill white -gravity center -size ${width}x40 caption:"${version} (${build}) ${commit}" ${base_path} +swap -gravity south -composite ${target_path}
}
Run Code Online (Sandbox Code Playgroud)

2. step - 更改构建阶段的顺序

您必须更改构建阶段的顺序,以便“复制捆绑资源”构建阶段之前订购“生成图标”构建阶段: 更改构建阶段的顺序

最初的想法和脚本代码来自Krzysztof Zab?ocki 的博客文章