iOS 10.3 Alternate Icons: what can you do and how it works ?In the first beta of iOS 10.3, Apple introduced the ability for an application to change its icon. You could ask when it would be useful. In fact, I see different cases:
Furthermore, you cannot change the icon unbeknownst to the user. Indeed, when you change the icon, there is an alert saying You have changed the icon for "Application Name". Here is a little demonstration of this feature in action: How it worksTo 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 ? DeclareFirst: 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:
ChangeOnce 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 iticon: UIApplication.shared.setAlternateIconName("it") { (error) in if let error = error { print("err: \(error)") } }ReadIf 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!") }FutureRight 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. Leave a Reply. |
|
Photo used under Creative Commons from nan palmero