这可以将替代图标应用于iOS应用程序吗?

Moh*_*ffi 11 uiapplication ios

我需要根据地区更改应用图标,这可能吗?

Kli*_*akM 35

是的,这可以从iOS 10.3开始.

首先,您需要在Info.plist文件中定义所有替代图标,您无法动态获取它们.

例如,这里我们定义了两个替代图标:"de"和"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>
Run Code Online (Sandbox Code Playgroud)

然后,您可以根据您喜欢的任何内容(游戏进度,天气状况,高级用户等)设置图标名称.要更改图标,请使用:

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

结果:

显示图标的Gif响应分段控件

这张GIF来自JulienQuéré的中篇文章.

  • 主键:在.xcassets文件夹的OUTSIDE中添加备用应用程序图标图像. (2认同)