Skip to content

Instantly share code, notes, and snippets.

@alessiorubicini
Created April 1, 2025 14:14
Show Gist options
  • Save alessiorubicini/22571ce4dc2e97f571c8fbc43dacc4bc to your computer and use it in GitHub Desktop.
Save alessiorubicini/22571ce4dc2e97f571c8fbc43dacc4bc to your computer and use it in GitHub Desktop.
Function to dinamically change app's icon on iOS and iPadOS devices that support alternate icons.
import UIKit
/// Changes the app's alternate icon.
/// - Parameter iconName: The name of the alternate icon. Pass `nil` to reset to the default icon.
func setAlternateIcon(_ iconName: String?) {
guard UIApplication.shared.supportsAlternateIcons else {
print("Alternate app icons are not supported on this device.")
return
}
let iconToSet = (iconName == "Mac") ? nil : iconName
UIApplication.shared.setAlternateIconName(iconToSet) { error in
if let error = error {
print("Failed to set icon: \(error.localizedDescription)")
} else {
print("App icon changed successfully to: \(iconToSet ?? "Default")")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment