5

My question is also same that others asked before.

I found that once you set the Icon for the Application we can't change the Application icon dynamically. Yes I agreed. If so we used Dynamic icons Apple Don't accept. But I accept there is some rules and regulation in apple.

So Here is my question : How to change the app icon dynamically. I am not going to put my Application in AppStore.

Everybody is telling it is not possible. I am not worrying about apples Rules. But yeh, worrying about the answer.

Anybody, Just guide me to Do this and don't tell me 'You Cant'.

Thanks in Advance.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Manikandan
  • 321
  • 2
  • 12

3 Answers3

9

iOS 10.3+

There is a method called setAlternateIconName: which is introduced in iOS 10.3, through which you can change the app's icon, however these icons should be predefined. It means that the icons should be added to the app's bundle and referenced in the info.plist.

Example:

A typical info.plist looks like:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>alternate_icon_name</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>alternate_icon_file</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>CFBundlePrimaryIcon</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>default_icon_file</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
</dict>

Implement the code like:

Objective C:

[[UIApplication sharedApplication] setAlternateIconName:@"alternate_icon_name" completionHandler:^(NSError * _Nullable error) {
    NSLog(@"Error...");
}];

Swift 3:

if UIApplication.shared.supportsAlternateIcons
{
    UIApplication.shared.setAlternateIconName("alternate_icon_name", completionHandler: { (error) in
        print(error ?? "")
    })
}

Before iOS 10.3

You cannot change the icon file dynamically, because the icon file name is stored on the application plist.

Application plist.

You cannot change the application plist dynamically, because it is stored on the application bundle which is readonly.

So your requirement is not possible.

Community
  • 1
  • 1
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • @Mithun MP : Ok.,thanks for ur answer. is it possible to give icon.png for Icon Files through Codes..,. – Manikandan Oct 22 '12 at 05:10
  • @dhanush: no, it is not possible, because if we need to change the icon, we need to edit the application.plist file. But that file is in application bundle which is readonly. So we cannot change it through code. – Midhun MP Oct 22 '12 at 05:12
  • @mithun MP no yar. we can give the icon through code. but the thing is we cannot change those icon file dynamically. – Manikandan Oct 22 '12 at 06:33
1

One way would be to rewrite the icon.png file programmatically. You'd need to search a private API that allows access to your App Resources filestystem

atastrophic
  • 3,153
  • 3
  • 31
  • 50
  • i tried to give icon.png through code. i succeed. if i change the icon image means it wont change the icon for the application – Manikandan Oct 22 '12 at 06:32
  • 2
    well technically it should, however the iOS might actually cache icon for the first time thus not reading every time from your App Resources. You might need to figure out how iOS handles these icons. – atastrophic Oct 22 '12 at 06:35
  • is there any links that provides the details about the icons (not for size of icons). – Manikandan Oct 22 '12 at 06:44
  • Unfortunately, none in my inventory .. =( – atastrophic Oct 22 '12 at 06:46
1

Before iOS 8 i tried one way which give me positive result at minimum once:

set icon.png as link to ../Documents/icon.png

But you need to force ask Springboard to redownload icons for installed applications (cause Springboard cache them)

Since iOS 8 this way does not work cause Documents folder was moved to dynamical path.

So you should find way to update readonly icon.png from bundle.

For apps installed to /Applications/ (through Cydia) - it's possible to do.

For apps installed via adhoc - There is no way to update readonly icon.png (as i know)

Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82