Is this possible to apply the alternative icon to the iOS application?

Yes, this is possible since iOS 10.3.

First, you need to define all alternative icons in your Info.plist file, you can’t fetch them dynamically.

In the example below we define 2 alternative icons: “de” and “fr”:

<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>
  </dict>
  <key>CFBundlePrimaryIcon</key>
  <dict>
   <key>CFBundleIconFiles</key>
   <array>
    <string>ic_none</string>
   </array>
  </dict>
 </dict>

Then you can set the icon name based on anything you like (game progress, weather conditions, premium user, etc.). To change the icon use:

UIApplication.shared.setAlternateIconName("de") { (error) in
    if let error = error {
        print("err: \(error)")
        // icon probably wasn't defined in plist file, handle the error
    }
}

Result:

Gif showing the icon changing in response to a segmented control

The gif is from a Medium article by Julien Quéré.

Leave a Comment