ios - Xcode/iOS - CFBundleAlternateIcons 未更改

标签 ios xcode info.plist cfbundleicons

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

完成一些故障排除后,我还尝试在预览中重新保存图标以确保它们是 PNG 文件,并删除其 Alpha channel ,结果没有任何变化。

我做错了什么?是 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");
}

这就是我所看到的,不管我点击更改为深色图标还是浅色图标。

false positive

这是我的 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 - property list

file structure

最佳答案

编辑:我现在已经解决了我的问题,尽管在线指南建议您将备用图标放置在单独的文件夹中,但只有当我将所述图标直接放置在 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>

属性列表:

property list, shows 'CFBundleAlternateIcons', with children 'dark' and 'light' for each alt icon type.

Xcode项目目录:

enter image description here

关于ios - Xcode/iOS - CFBundleAlternateIcons 未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64426880/

相关文章:

ios - 在 UIView 子类中声明的委托(delegate)在 UIViewController 中不起作用?

ios - 捆绑软件使用与Apple应用程序关联的捆绑软件名称或显示名称

macos - 更改 info.plist 文件中的版本,以便正确的版本将显示在 mac finder 中

iphone - 我最近发布的应用程序更新在 info.plist 文件中没有最新/正确的值

xcode - applicationDidFinishLaunching 未调用

ios - 如何使用 Realm 保存图像数组

ios - 如何在 Storyboard中使用 xib 文件作为自定义 View

ios - 发出多个异步请求,但仅等待一个

python - 在 Xcode 下运行 virtualenv python

android - 如何将 SliverGrid 集成到 TabBarView 中?