我一直在尝试使用 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");
}
这就是我所看到的,不管我点击更改为深色
图标还是浅色
图标。
这是我的 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>
最佳答案
编辑:我现在已经解决了我的问题,尽管在线指南建议您将备用图标放置在单独的文件夹中,但只有当我将所述图标直接放置在 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>
属性列表:
Xcode项目目录:
关于ios - Xcode/iOS - CFBundleAlternateIcons 未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64426880/