问题描述
我一直在尝试使用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>
解决方法
我通过如下定义CFBundleIconFiles
中的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>