【问题标题】:Xcode/iOS - CFBundleAlternateIcons not changingXcode/iOS - CFBundleAlternateIcons 没有改变
【发布时间】:2021-02-02 04:51:36
【问题描述】:

我一直在尝试使用 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>

【问题讨论】:

    标签: ios xcode info.plist cfbundleicons


    【解决方案1】:

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


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

    之前:

    <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>
    

    【讨论】:

    • 查看赏金 cmets 以了解我为什么在我已经回答的问题上设置赏金。
    猜你喜欢
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 2018-07-01
    • 2011-12-18
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 2022-06-18
    相关资源
    最近更新 更多