自 iOS 10.3+ 起(自 2017 年起),这是可能的,但对于 Cordova 应用程序(如 Ionic)来说,这将取决于特定的插件。
你可以试试这个插件(只有iOS,不是Android)cordova-plugin-app-icon-changer
安装使用:
cordova plugin add cordova-plugin-app-icon-changer
检查支持:
AppIconChanger.isSupported(function(supported) {
if (supported) {
...
} else {
...
}
});
更换图标:
AppIconChanger.changeIcon({
iconName: "<icon name here>",
suppressUserNotification: true
}, function() {
// Changed...
}, function(err) {
// If failed ...
});
更多插件见:https://cordova.apache.org/plugins/?q=icon
注意:如果需要,您可以使用 setAlternateIconName(_:completionHandler:) 实现自己的插件(或者如果您想创建原生应用程序)
使用supportsAlternateIcons检查是否支持交换很重要
将图片放入“资产”后,转到Info.plist (CFBundleIcons) 添加与图片对应的项目CFBundleAlternateIcons,如示例中所示:
▼ CFBundleIcons
▼ CFBundleAlternateIcons
▼ <icon name here>
▶ CFBundleIconFiles
如果您需要对 iPad 的支持,结构应该类似于:
▼ CFBundleIcons
▼ CFBundleAlternateIcons
▼ <icon name here>
▶ CFBundleIconFiles
▼ CFBundleIcons~ipad
▼ CFBundleAlternateIcons
▼ <icon name here>
▶ CFBundleIconFiles
Cordova 项目的图片示例(例如 Ionic)
Android Cordova 插件
到目前为止,我还没有找到适用于 Android 的现有插件,但根据这个答案 How to change an application icon programmatically in Android?(我目前无法测试答案)显然可以更改图标。