Before iOS 18, I have the following code that works well:
let icons = Bundle.main.infoDictionary!["CFBundleIcons"] as! [String: Any]
let primaryIcon = icons["CFBundlePrimaryIcon"] as! [String: Any]
let iconName = primaryIcon["CFBundleIconName"] as! String
return UIImage(named: iconName)!
The iconName
is "AppIcon"
, and it returns the 1024×1024 image. Now using iOS 18 base SDK, UIImage(named: iconName)
is nil, causing a crash in my app.
More details:
- If I build using base SDK iOS 17, it runs fine on both iOS 17 and iOS 18.
- If I build using base SDK iOS 18 (with deployment target iOS 17), it crashes on both iOS 17 and iOS 18.
I have tried the answers from How to get UIImage of AppIcon?, but the result isn’t as good. Specifically, the following code that uses CFBundleIconFiles
instead of CFBundleIconName
:
let icons = Bundle.main.infoDictionary!["CFBundleIcons"] as! [String: Any]
let primaryIcon = icons["CFBundlePrimaryIcon"] as! [String: Any]
let iconFiles = primaryIcon["CFBundleIconFiles"] as! [String]
return UIImage(named: iconFiles[0])!
The iconFiles[0]
returns AppIcon60x60
, which uses [email protected]
in main bundle which is 120×120, a lot lower than 1024×1024.
I have done the following research:
-
In my app setup, I use asset catelog (
Assets.xcassets -> AppIcon
), with a image file calledicon1024.png
that is 1024×1024. -
In
General
tab of the target setting, I setAppIcon
as the app icon. -
in the resulting product (
.app
file), I see 3 related files:
- [email protected]
- AppIcon76x76@2x~ipad.png
- Assets.car
Then I use “Asset Catelog Tinker” app to inspect Assets.car
, I got a single file icon1024.png
.
I tried building with both iOS 17 and iOS 18, and got the same .app
folder structure.
This means that when building with base SDK iOS 17, when calling UIImage(named: "AppIcon")
, it somehow magically loads Assets.car/icon1024.png
file. But this doesn’t work anymore when building for iOS 18.