-
-
Save bmontag/b57f6d456b4aeb4483a0678453652089 to your computer and use it in GitHub Desktop.
Change Programmatically your App Icon
This file contains 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
var current: BMAppIcon { | |
return BMAppIcon.allCases.first(where: { | |
$0.name == UIApplication.shared.alternateIconName | |
}) ?? .classic | |
} | |
func setIcon(_ appIcon: BMAppIcon, completion: ((Bool) -> Void)? = nil) { | |
guard current != appIcon, | |
UIApplication.shared.supportsAlternateIcons | |
else { return } | |
UIApplication.shared.setAlternateIconName(appIcon.name) { error in | |
if let error = error { | |
print("Error setting alternate icon \(appIcon.name ?? ""): \(error.localizedDescription)") | |
} | |
completion?(error != nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment