How to set alternate icon for an iOS app programmatically?

Hello iOS Devs,
Hope you guys doing well in this COVID-19 situation. Stay Safe At Home.

In this week Xcode 11.4 released. Many new things came with that. You can check What’s new in Xcode 11.4? blog for the same.

App icon change functionality is available from iOS 10.3. In this tutorial we will learn to set an alternate icon for an iOS application programmatically.

Let’s Start!

Pre-Requirements

We require one default icon and another alternate icon. Alternate icon will be in @2x and @3x sizes. So the file name would be YourAlternateIcon@2x.png (120 x 120) and YourAlternateIcon@3x.png (180 x 180).

Add your app icon in Assets.xcassets as follows:

Add your alternate app icons in your project as follows (I have created Resources folder for it):

Ready your Info.plist for Alternate App Icon

Update your plist file for alternate app icon as follows:

  1. Create new row and select “Icon files (iOS 5)” in Info.plist.
  2. Create new entry CFBundleAlternateIcons
  3. Create new entry for alternative icon (i.e. JerryIcon – Dictionary)
  4. Register your alternate icon file name to item in CFBundleIconFiles

Here I am adding Info.plist as source code to see what you need to update in your plist:

Let’s Do The Code

List of methods provided by Apple which is used to Managing the App’s Icon:

We will use setAlternateIconName method to change icon for the application.

To use default/primary app icon use following code:

Note: Whenever you set alternate icon, Apple will display default alert like: You have changed the icon for “YourApplicationName” You can check in following video.

Final Output!

This video is posted on my youtube channel. Like, Share and Subscribe for the content related to iOS Development, Swift Language and Apple News!

Sample code is available at my github.

I hope you learned something. If you did, feel free to share this article with a friend or on social media. Let me know if you have any questions, comments or feedback – either via Twitter or email.

Stay Safe At Home. Learn Something New. Share To The World.
Happy Coding 🙂