Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

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

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...