Is this possible to apply the alternative icon to the iOS application?
Asked Answered
C

2

13

I need to change the app icon based on region, is this possible?

Compare answered 31/1, 2017 at 6:25 Comment(0)
T
39

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é.

Tamikatamiko answered 31/1, 2017 at 6:32 Comment(3)
Major Key: Add your alternate app icon images OUTSIDE of .xcassets folder.Tractor
Is there a limit on the amount of images you can change between? @TamikatamikoGold
@Pavan, No limit at all. Only limit is whatever you have inside your bundle.Mb
S
3

This feature available in 10.3 (Beta)

Discussion Use this method to change your app's icon to its primary icon or to one of its alternate icons. You can change the icon only if the value of the supportsAlternateIcons property is true.

You must declare your app's primary and alternate icons using the CFBundleIcons key of your app's Info.plist file. For information about how to configure alternate icons for your app, see the description of the CFBundleIcons key in Information Property List Key Reference.

Take a look at:

apple documentation

Shawana answered 31/1, 2017 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.