Swift API to change application icon without any limit nor having a dialog presented.
This uses Apple private APIs. It did not trigger App Store rejection for me but, do tell it if it does for you.
Copy DynamicIcon.swift to your project.
To add a package dependency to your Xcode project, select File > Add Package and enter this repository's URL (https://github.com/g-cqd/DynamicIcon).
First, create AppIcon iconsets in your assets and use their names in the code below.
You can reset the icon to the original one by passing nil
as argument of the method.
import SwiftUI
import DynamicIcon
struct ContentView: View {
struct Icons {
static var blue = "AppIcon1"
static var red = "AppIcon2"
}
var body: some View {
VStack {
Button("Set Icon to Blue") {
DynamicIcon.setAlternateIconName(Icons.blue)
}
Button("Set Icon to Red") {
DynamicIcon.setAlternateIconName(Icons.red)
}
Button("Reset") {
DynamicIcon.setAlternateIconName(nil)
}
}
}
}
- To Bryce Bostwick for AnimatedAppIcons that served as boilerplate for the package code.