In my apps, I have a requirement to display an image of the application icon is certain circumstances. This is fairly straightforward for iOS/iPadOS and it used to be straightforward for macCatalyst.
For MacCatalyst, this is no longer true (at least since macOS 26). This is because the app icon is now stored as an .icns file and (in the case of using an IconComposer icon), the `'png' in the Asset Catalog now has an unknown name. So the following code no longer works:
public extension Bundle {
var icon: UIImage? {
#if targetEnvironment(macCatalyst)
guard let iconName = infoDictionary?["CFBundleIconName"] as? String else { return nil }
return UIImage(named: iconName, in: self, compatibleWith: nil)
#else
guard let icons = infoDictionary?["CFBundleIcons"] as? [String : Any] else { return nil }
guard let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String : Any] else { return nil }
guard let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String] else { return nil }
guard let file = iconFiles.last else { return nil }
return UIImage(named: file, in: self, compatibleWith: nil)
#endif
}
The obvious solution is to place an Image in the Asset Catalog which I can access, but this is a maintenance headache.
What I would actually like to do is either
create a UIImage directly from the .icns file, or
access the .png file in the Asset Catalog (which has a name beginning with the icon file name, but has additional characters in its name that I don't know).
Can you help?
3
0
629