23

I have a problem with changing app's icon on iPad. Everything is working fine on iPhone but on iPad I get this error :

[default] Failed to set preferredIconName to AI-Gorgosaurus for ...:0> error: Error Domain=NSCocoaErrorDomain Code=4 "The file doesn’t exist." UserInfo={NSUnderlyingError=0x600000248a30 {Error Domain=LSApplicationWorkspaceErrorDomain Code=-105 "iconName not found in CFBundleAlternateIcons entry" UserInfo={NSLocalizedDescription=iconName not found in CFBundleAlternateIcons entry}}} App icon failed to due to The file doesn’t exist.

I searched ad found that I need to add ~ipad in CFBundleIconFiles but still get the same error!.

Here is the code:

  func changeIcon(to name: String?) {
        //Check if the app supports alternating icons
        guard UIApplication.shared.supportsAlternateIcons else {
            return;
        }

        //Change the icon to a specific image with given name
        UIApplication.shared.setAlternateIconName(name) { (error) in
            //After app icon changed, print our error or success message
            if let error = error {
                print("App icon failed to due to \(error.localizedDescription)")
            } else {
                print("App icon changed successfully.")
            }
        }
    }

enter image description here

I just tested on another project and works fine !!! but not on my current project why ?! have you any idea?

3
  • What are the images sizes for iPad? Jun 2, 2019 at 0:12
  • @DanielSpringer I just used 700 × 700 px for all devices.
    – iOS.Lover
    Jun 3, 2019 at 14:26
  • I can't get it to work on iPad even with bigger image sizes Nov 4, 2019 at 5:29

6 Answers 6

41

Your info.plist is structured incorrectly.

You have:

- CFBundleIcons
  - CFBundleAlternateIcons
    - Icon Name
      - CFBundleIconFiles
      - CFBundleIconFiles~ipad

But it should be:

- CFBundleIcons
  - CFBundleAlternateIcons
    - Icon Name
      - CFBundleIconFiles
- CFBundleIcons~ipad
  - CFBundleAlternateIcons
    - Icon Name
     - CFBundleIconFiles

Basically, once you have it working with iPhone icons, CFBundleIcons, duplicate the entire tree as CFBundleIcons~ipad. The iPad files shouldn't be nested under CFBundleIcons at all.

You're mixing up CFBundleIcons~ipad and CFBundleIconFiles~ipad (which isn't a valid key).

Screenshot

10
  • 3
    What are the images sizes for iPad? Jun 2, 2019 at 0:13
  • 2
    @DanielSpringer Ah, that's the "Raw Keys and Values" verses the friendly names. Right click on the keys to toggle that back and forth.
    – Dave Wood
    Nov 4, 2019 at 7:07
  • 1
    @DaveWood 🤗 hugs Dave Nov 4, 2019 at 7:15
  • 2
    Thanks for sharing this Dave, saved me a lot of time. May 9, 2020 at 17:28
  • 1
    This works, thansk a lot
    – onmyway133
    Dec 6, 2021 at 22:13
21

Attempting to give a more re-useable (easy to copy/paste) version of this answer.

1) You need images of the following names and sizes added as regular .png files (no asset catalogues)

.../AppIcon-Dark/iPad-app.png
  pixelWidth: 76
.../AppIcon-Dark/iPad-app@2x.png
  pixelWidth: 152
.../AppIcon-Dark/iPad-pro@2x.png
  pixelWidth: 167
.../AppIcon-Dark/iPhone-app@2x.png
  pixelWidth: 120
.../AppIcon-Dark/iPhone-app@3x.png
  pixelWidth: 180

you can then add/insert the following in your info.plist

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>AppIcon-Dark</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>iPhone-app</string>
            </array>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>AppIcon</string>
        </array>
    </dict>
</dict>
<key>CFBundleIcons~ipad</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>AppIcon-Dark</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>iPad-app</string>
                <string>iPad-pro</string>
            </array>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>AppIcon</string>
        </array>
    </dict>
</dict>

I then set my icon with the following

func updateIcon() {
    if #available(iOS 13.0, *) {
        let dark = window?.traitCollection.userInterfaceStyle == .dark

        let currentIconName = UIApplication.shared.alternateIconName
        let desiredIconName:String? = dark ? "AppIcon-Dark" : nil

        if currentIconName != desiredIconName {
            UIApplication.shared.setAlternateIconName(desiredIconName) {
                (error) in
                print("failed: \(String(describing: error))")
            }
        }
    }
}
1
  • Thank you for this! It was impossible to find this information in articles on the topic. They just sorta ignore the fact there's multiple icon sizes
    – Jacob
    Dec 6, 2020 at 17:08
4

Please make these changes to your plist file for setting alternate icons for iPhone and iPad.

enter image description here

1
  • What does UIPrerenderedIcon do and why do you have one NO and the other YES? May 13, 2019 at 12:11
0

What I have noticed is that your plist has UIPrerenderedIcon set to NO

Change it to YES

It might be that the issue is with the rendering

Edit 1: add the .png extension to see if it helps

EDIT 2: Try changing the new icon's filename to ipadAlternate.png. Then change to the same name in the plist as it looks like there is some kind of mismatch with your plist and the icon file itself

EDIT 3: Have you cleaned the DerivedData folder? I had an issue a while ago and nothing helped including cleaning the project etc. But I tried deleting everything in the /Users/YOURUSERNAME/Library/Developer/Xcode/DerivedData/ folder and it started working again. It is worth giving it a go.

EDIT 4: Try doing step from EDIT 3. Then restart your project and delete all the alternative icon files from it. Choose move to trash and then CMD+SHIFT+K to clean. Then select CMD+B to build. Next add the icons back where they were. Check that the target is selected correctly and copy items if needed to be selected. For some reason Xcode lost track of your file and it is showing an error, no file.

If that will not help then try the above steps. But first try moving the whole project to a different folder.

EDIT 5: There is one more idea which you might try for yourself. Try deleting the plist file in the current project (keep a backup copy of it before deleting) then start a new project where the icon changing works fine. Add the plist from that project to this one. Check if the icon changing works. If yes then add all the missing keys you had in the previous project.

WARNING: This is a last resort but this may work. Start a new project and set it up with the icons which you want alternating. Check if they work first then add all the code and dependencies from the project where it doesn't work. Just don't override the PLIST files.

EDIT 6: Try deleting the app from the simulator or the device you are trying it on and reinstall it. The whole issue might be with the update and the leftovers from the previous version of the app.

EDIT 7: Try copying the project to another mac and see if the problem persists. Which xcode version are you using?? If it is Xcode 9, perhaps try using the Xcode 10 beta.

11
  • Add the .png extension see if it helps Aug 25, 2018 at 8:36
  • Try changing the new icons filename to ipadAlternate.png and then change to the same in the plist as it looks like there is some kind of mismatch with your plist and the icon file itself Aug 25, 2018 at 8:41
  • Could you share your code on github or somewhere so I could either fork it or contribute?? Aug 25, 2018 at 14:00
  • It's a big project, it works if I create a new project but not work on my current project !!! that's my problem. !!!
    – iOS.Lover
    Aug 25, 2018 at 14:02
  • Just share a part of it that will compile and have the error then or you can make another branch on which I could try to help. Aug 25, 2018 at 14:59
-1

The error is showing a different file name than the one in .plist CFBundleAlternateIcons. Make sure you assign a correct Filename in and it actually exists in the project folder.

Error Shows AI-Gorgosaurus as the file name. .plist screenshot shows AI-Diabloceratops~ipad, also please remove ~ symbol from the file name.

Do a clean and build the project after you're sure file is correct. Make sure you have @2x and @3x version of your Icons in your project folder.

Read Kaiyuan Xu answer for a more clear picture on how to use CFBundleAlternateIcons.

2
  • The image is old, I checked everything.
    – iOS.Lover
    Aug 29, 2018 at 7:45
  • Ok, let’s do screen sharing, I need to get a more clear view of the problem. Aug 29, 2018 at 11:02
-2

With below structure i'm able to change icon in iPad:

    if #available(iOS 10.3, *) {
        let newAppIconName = "Icon2"

        guard UIApplication.shared.alternateIconName != newAppIconName else { return }

        UIApplication.shared.setAlternateIconName(newAppIconName)
    }
}

Plist Code:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>AppIcon</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <true/>
    </dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>Icon2</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>icon60</string>
            </array>
            <key>CFBundleIcons~ipad</key>
            <array>
                <string>iTunesArtwork80.png</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <true/>
        </dict>
    </dict>
</dict>

enter image description here

15
  • Thank you but I am doing exactly like this but what I get is the error!
    – iOS.Lover
    Aug 21, 2018 at 13:56
  • CFBundleAlternateIcons entry" UserInfo={NSLocalizedDescription=iconName not found in CFBundleAlternateIcons entry}}} App icon failed to due to The file doesn’t exist.
    – iOS.Lover
    Aug 21, 2018 at 13:57
  • 1
    You can see i am using CFBundleIcons~ipad and you are CFBundleIconsFiles~ipad.
    – iVarun
    Aug 21, 2018 at 13:59
  • Could you please try to change your code with my code. Coz it is working for me.
    – iVarun
    Aug 21, 2018 at 14:02
  • 1
    Actually i left the office but can surely help tomorrow.
    – iVarun
    Aug 21, 2018 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.