The way to change your apps icon at run time.
Environment: Xcode 13.1, iOS 15
-
Select
Assets
folder and click the+
button at the bottom then selectiOS
->iOS App icon
to create a new icon folder with a specific name -
Prepare icons that match the required size and drag them to the corresponding places.
-
Repeat the above steps if you want to create multiple alternate icons.
-
Selected the
Build Settings
after selecting the desired target in theTargets
, findAsset Catalog Compiler - Options
section. -
Select
Alternate App Icon Sets
and add the name of the icon assets (each name occupies one line). -
Change the value of the
Include All App Icon Assets
toYes
. -
Select
Primary App Icon Set Name
specified the primary app icon asset name.
Call the following code to change the icon:
// Set the iconName to nil to use the primary icon.
let iconName = "my-icon-name"
UIApplication.shared.setAlternateIconName(iconName) { (error) in
if let error = error {
print("Failed request to update the app’s icon: \(error)")
}
}
The current icon's name is available through the property alternateIconName
.