1

我一直在尝试使用 CFBundleAlternateIcons 更改我的应用程序图标,但没有任何反应。我实际上正在使用 Flutter SDK 的插件 -flutter_dynamic_icon当我使用插件更改图标时,它会显示“应用程序图标更改成功”,就好像没有任何问题一样。

在进行了一些故障排除后,我还尝试在预览中重新保存图标以确保它们是 PNG 文件,并删除它们的 alpha 通道,结果没有任何变化。

我究竟做错了什么?是 Info.plist 问题吗?我的图标是否保存不正确?我是否错误地要求更改图标?

这就是我尝试更改 dart lang 中的图标的方式:

try {
  if (await FlutterDynamicIcon.supportsAlternateIcons) {
    await FlutterDynamicIcon.setAlternateIconName("dark");
    print("App icon change successful");
    return;
  }
} on PlatformException {} catch (e) {
  print("icon couldn't be changed");
}

这就是我所看到的,不要介意我单击以更改为dark图标或light图标。

假阳性

这是我的 Info.plist / 文件结构:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>light</key>
        <dict>
            <key>UIPrerenderedIcon</key>
            <string>NO</string>
            <key>CFBundleIconFiles</key>
            <array>
                <string>light</string>
            </array>
        </dict>
        <key>dark</key>
        <dict>
            <key>UIPrerenderedIcon</key>
            <string>NO</string>
            <key>CFBundleIconFiles</key>
            <array>
                <string>dark</string>
            </array>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>dark</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
</dict>

info.plist - 属性列表

文件结构

4

1 回答 1

1

编辑:我现在已经解决了我的问题,尽管在线指南建议您将备用图标放在单独的文件夹中,但我的情况只有在我将所述图标直接放在Runner目录中时才有效。


我通过如下定义CFBundleIconFilesin来解决这个问题。Info.plist这是一个微妙的变化,但可以决定过程的成败。

前:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>light</key>
        <dict>
            <key>UIPrerenderedIcon</key>
            <string>NO</string>
            <key>CFBundleIconFiles</key>
            <array>
                <string>light</string>
            </array>
        </dict>
        <key>dark</key>
        <dict>
            <key>UIPrerenderedIcon</key>
            <string>NO</string>
            <key>CFBundleIconFiles</key>
            <array>
                <string>dark</string>
            </array>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>dark</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
</dict>

后:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>light</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>light</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>light</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>dark</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>dark</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
</dict>
于 2020-10-19T14:23:49.043 回答