我试图通过代码改变应用程序图标,但它似乎不起作用。下面是我的info.plist
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon_60pt</string>
</array>
</dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>AppIcon-2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon.dark_60pt</string>
</array>
</dict>
</dict>
</dict>下面是我用来更改图标的代码:
@objc func changeIcon() {
//Check if the app supports alternating icons
guard UIApplication.shared.supportsAlternateIcons else {
return;
}
let name = "icon.dark_60pt"
//Change the icon to a specific image with given name
UIApplication.shared.setAlternateIconName(name) { (error) in
//After app icon changed, print our error or success message
if let error = error {
print("App icon failed to due to \(error.localizedDescription)")
} else {
print("App icon changed successfully.")
}
}
}最后,下面是带有应用图标的文件夹:应用图标文件夹屏幕截图
正如您所看到的,我在任何地方都使用相同的名称"icon.dark_60pt",但我仍然收到一个错误“文件不存在”。
应用程序图标失败,因为错误的Domain=NSCocoaErrorDomain Code=4“文件不存在”。_setAlternateIconName:forIdentifier:withIconsDictionary:error:}},{_LSLine=191,NSUnderlyingError=0x6000026e85d0 {错误Domain=LSApplicationWorkspaceErrorDomain代码=-105 "iconName not in CFBundleAlternateIcons entry“UserInfo={_LSLine=179,NSLocalizedDescription=iconName未在CFBundleAlternateIcons条目中找到,_LSFunction=-LSAltIconManager UserInfo= _LSFunction=-LSAltIconManager _setAlternateIconName:forIdentifier:withIconsDictionary:error:}
我做错了什么?
发布于 2020-12-23 07:16:22
我认为您必须使用图标的名称,而不是文件的名称。用以下方式更改let名称行:
let name = "AppIcon-2"https://stackoverflow.com/questions/65387011
复制相似问题