3

I want to change the app icon dynamically. I receive the image from the server. How do I use that image as alternative app icon. Please make sure the answer is clear. (but as I know, the alternative app icon file should be in our project plist file).

Thanks in advance.

Nadeem Iqbal
  • 2,357
  • 1
  • 28
  • 43
user3467582
  • 49
  • 1
  • 5

2 Answers2

7

You cannot change your app icon with an image downloaded from a server at runtime. From the documentation:

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.

In order to dynamically set an app icon, you must be able to define it in your Info.plist, but your Info.plist is included in your app bundle, and your app bundle is read-only, so you do not have runtime write access to your Info.plist file. Thus, you cannot change your app icon to an image dynamically downloaded at runtime

Michael Hulet
  • 3,253
  • 1
  • 16
  • 33
  • can you set the info plist to an image that will then be downloaded at runtime? – zumzum Jan 03 '20 at 18:04
  • I don't think so. I believe they need to be compiled into your app's bundle so iOS knows where to find them. There isn't a way to set it to a specific file, only a name that you list in your `Info.plist`, and I don't think iOS checks your app's runtime-writable directories – Michael Hulet Jan 03 '20 at 20:22
1

Apple launches a cool function so that developers are able to programmatically change the app icon.

In Apple's API document, there are 3 things worth a glance:

var supportsAlternateIcons: Bool { get }
var alternateIconName: String? { get }
func setAlternateIconName(String?, completionHandler: ((Error?) -> Void)? = nil)

Info.plist

Now we just call the method:

changeIcon(to: "icon-imageName")

Reference: https://developer.apple.com/documentation/uikit/uiapplication/2806815-supportsalternateicons

double-beep
  • 5,031
  • 17
  • 33
  • 41
Byka
  • 89
  • 1
  • 10