How it works

To show how this works, I made a dummy supporter application. You have to say which is your favorite national sports team, and it changes the app icons with theses colors. You can find the source code here on Github. So, how is it done ?

Declare

First: you should declare all alternate icons in the info.plist file. The problem is that you should give up assets catalog for icons. Indeed, it seems not to be compatible with this feature :/. So, we should go back to the old method with simple .png resources. Everything is declared in CFBundleAlternateIcons. In this demo, it gives:

<key>CFBundleIcons</key>

<dict>

<key>CFBundleAlternateIcons</key>

<dict>

<key>de</key>

<dict>

<key>CFBundleIconFiles</key>

<array>

<string>ic_de</string>

</array>

<key>UIPrerenderedIcon</key>

<false/>

</dict>

<key>fr</key>

<dict>

<key>CFBundleIconFiles</key>

<array>

<string>ic_fr</string>

</array>

<key>UIPrerenderedIcon</key>

<false/>

</dict>

<key>it</key>

<dict>

<key>CFBundleIconFiles</key>

<array>

<string>ic_it</string>

</array>

<key>UIPrerenderedIcon</key>

<false/>

</dict>

</dict>

<key>CFBundlePrimaryIcon</key>

<dict>

<key>CFBundleIconFiles</key>

<array>

<string>ic_none</string>

</array>

</dict>

</dict>

We defined 3 alternate icons:

de (which is bound to file ic_de )

) fr (which is bound to file ic_fr )

) it (which is bound to file ic_it )

And we have the primary icon (the default one) bound to file ic_none .

Change

Once the icons are declared, we simply have to call setAlternateIconName(_:completionHandler:) on UIApplication shared instance with one of the declared icon names. For instance, if we want it icon:

UIApplication.shared.setAlternateIconName("it") { (error) in

if let error = error {

print("err: \(error)")

}

}

Read

If you want to know which icon is currently set up, just read alternateIconName on UIApplication shared instance:

if UIApplication.shared.alternateIconName == "it" {

print("Viva italia")

} else if UIApplication.shared.alternateIconName == "fr" {

print("Allez les bleus!")

}

Future

Right now, this feature is still beta. So it might evolve in the future. Maybe Apple will allow the user to block the icon change (right now, the user is just informed, he cannot say no). Moreover, Apple did not say what is allowed, and what is not in the customization of icons.