Created
April 1, 2025 14:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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